PHP index.PHP文件从子目录位置获取其他页面内容
如何在服务器根目录中只获取PHP index.PHP文件从子目录位置获取其他页面内容,php,html,.htaccess,server-side,Php,Html,.htaccess,Server Side,如何在服务器根目录中只获取索引.php,并将所有链接页面(如/about.php/contact.php等)放置在服务器中的子目录(如/pages/dist)中?如果有人访问example.com/about.php它会从/pages/dist/[filename.php]?获得内容,我发现有两种方法可以做到这一点 将htaccess与regex一起使用: 使用,可以将基本url链接到如下文件夹: RewriteEngine On RewriteRule ^(?!index\.php)([\w-
索引.php
,并将所有链接页面(如/about.php
/contact.php
等)放置在服务器中的子目录(如/pages/dist
)中?如果有人访问example.com/about.php
它会从/pages/dist/[filename.php]
?获得内容,我发现有两种方法可以做到这一点
RewriteEngine On
RewriteRule ^(?!index\.php)([\w-_]+)$ pages/dist/$1.php [QSA,L]
RewriteRule ^(?!index\.php)([\w-_]+\.php)$ pages/dist/$1 [QSA,L]
RewriteEngine ON
RewriteRule "test.php" "page/dist/test.php"
RewriteRule "test2.php" "page/dist/test2.php"
RewriteRule "test3.php" "page/dist/test3.php"
...
第二行是以没有.php标记结尾的文件,第三行是以.php标记结尾的文件。
这样做的目的是,如果用户在url www.example.com/test.php中输入,它将显示www.example.com/page/dist/test.php上的内容,即使用户去掉php标记,但如果用户输入index.php,它将保持不变
RewriteEngine On
RewriteRule ^(?!index\.php)([\w-_]+)$ pages/dist/$1.php [QSA,L]
RewriteRule ^(?!index\.php)([\w-_]+\.php)$ pages/dist/$1 [QSA,L]
RewriteEngine ON
RewriteRule "test.php" "page/dist/test.php"
RewriteRule "test2.php" "page/dist/test2.php"
RewriteRule "test3.php" "page/dist/test3.php"
...
如果我错了,请纠正我。你真的希望从URL中删除.php吗?不,这没关系,因为我使用了带有
选项+多视图的.htacces来让它在没有扩展的情况下也能工作。只是希望在子目录中包含其他文件。我不知道为什么它被否决了这个问题这么糟糕吗?如果可能的话,这是一个问题吗?或者您在尝试实现这一点时遇到了问题?这更像是一个问题,因为我不知道是否可以只使用一个index.php
。我可以使用include来实现这一点,但我需要将所有页面添加到根目录,比如:about.php
,并将位于/pages/dist/about.php/
的文件包含到服务器,这对我的项目不利,因为我想管理从/pages/dist/[filename.php]显示的所有页面
我在一个有很多页面的非常复杂的项目中使用任务运行程序,不确定这里是否有人知道是否可以这样做,这就是我问这个问题的原因。