我正在尝试从我的子文件夹网址中删除index.php。因此,如果有人访问 www.mysite.com/sub-folder/index.php,我希望该网址重定向到 www.mysite.com/sub-folder/。 我已在子文件夹中添加了以下 htaccess 文件,但它不起作用。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sub-folder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sub-folder/index.php [L]
</IfModule>
有人可以帮我解决这个问题吗?谢谢
最佳答案
您可以在/subfolder/.htaccess
中使用此.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sub-folder/
# remove index.php from URLs
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ $1 [L,R=302,NC,NE]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
关于regex - 使用 htaccess 从子文件夹中删除 index.php 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27075735/