我目前使用以下htaccess代码删除所有.php扩展名:
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule .* - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+[^/])/?$ $1.php [L]
我一直在尝试使用以下htaccess代码在内部重定向或向文件中添加隐藏的查询参数
RewriteRule ^myfile/?([^/])?/?$ myfile.php?m=$1 [L]
但它不起作用。
答案 0 :(得分:1)
.htaccess中的规则顺序很重要,因此您的新规则应该高于所有其他规则。这应该是你的.htaccess:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^myfile/?([^/])?/?$ myfile.php?m=$1 [L,QSA,NC]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule .* - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+[^/])/?$ $1.php [L]