【发布时间】:2022-01-11 00:40:13
【问题描述】:
我的根目录中有这些文件,在页面内我有 php 文件,例如 projects.php,我尝试编写 .htaccess 规则以获取文件,例如 xxx.com/projects 从 / 打开文件pages/projects.php 并与以下内容一起使用
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} . [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# No file extension on request then append .php and rewrite to subdir
RewriteCond %{REQUEST_URI} /(.+)
RewriteRule !\.[a-z0-4]{2,4}$ /pages/%1.php [NC,L]
# All remaining requests simply get rewritten to the subdir
RewriteRule (.*) /pages/$1 [L]
我的问题是当我转到根 xxx.com 而不是打开 index.php 它的打开页面目录时,但如果我明确地转到 xxx.com/index.php 它可以工作。 我不希望 index.php 显示在 url 我需要从我的规则中排除根并使其打开 index.php 而 url 保持 xxx.com
【问题讨论】:
-
"从我的规则中排除根目录并使其打开 index.php" - 在文档根目录中打开
index.php或/pages/index.php?
标签: php regex apache .htaccess mod-rewrite