PHP / .htaccess - 重定向到特定文件夹


PHP / .htaccess - Redirect to specific folder

我正在创建一个PHP项目,文件夹结构如下所示:

includes/ 
pages/
config/

理论上,所有页面都将进入pages文件夹。但是,每当有人访问该网站时,在特定页面上:(即)www.mysite.com/help我希望它查看pages/文件夹内部,而不是认为它位于文档的根目录上。

我可以使用 PHP/.htaccess 实现这一点吗 - 我已经用谷歌搜索了这个问题,看不到任何相关信息

您可以在/root/.htaccess 中使用以下规则:

RewriteEngine on
#if "/document_root/pages/foo" is an existent file
RewriteCond %{DOCUMENT_ROOT}/pages/$1 -f
#rewrite /foo to /pages/foo
RewriteRule ^(.*)$ /pages/$1 [NC,L]

Apache 支持 URL 重写,如下所述:http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

.htaccess

RewriteEngine on
RewriteRule ^/?help/?(.*) /pages/$1  [L]