regex - 使用 htaccess 从子文件夹中删除 index.php 不起作用

标签 regex apache .htaccess mod-rewrite redirect

我正在尝试从我的子文件夹网址中删除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/

相关文章:

regex - 使用 oracle REGEXP_LIKE 函数查找具有相同数字(包括破折号)的 SSN

c# - 如何使用 Regex.Replace 从字符串中删除数字?

javascript - 如何使用正则表达式仅提取匹配字符串的一部分?

php - PHP MySQL 查询中的 MySQL/Apache 错误

.htaccess - HTACCESS 捕获文件名作为请求参数

php - Apache Mod_Rewrite 定义 URL 变量

c# - 如何设置重复正则表达式?

apache - WAMP 2.5 (Apache 2.4.9) 允许从 LAN 上的所有计算机进行访问

php - Laravel 中的长轮询(sleep() 函数使应用程序卡住)

javascript - 仅当网站发生更改时才设置缓存 header (php、htaccess)