Apache PHP中查询字符串的HTACCESS重写规则
我有我的网址 我需要重写一个规则,使即使我删除了问号,链接将与以前一样工作,所以我的url需要被删除 目前,在.htaccess文件中,我只有一条规则,即打开php时不带扩展名.phpApache PHP中查询字符串的HTACCESS重写规则,apache,.htaccess,mod-rewrite,url-rewriting,friendly-url,Apache,.htaccess,Mod Rewrite,Url Rewriting,Friendly Url,我有我的网址 我需要重写一个规则,使即使我删除了问号,链接将与以前一样工作,所以我的url需要被删除 目前,在.htaccess文件中,我只有一条规则,即打开php时不带扩展名.php RewriteEngine On RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L] RewriteCond %{REQUEST_FILENAME}.php -f
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
谢谢大家! 对于显示的示例,请尝试以下htaccess规则文件。请确保在测试URL之前清除浏览器缓存
RewriteEngine On
##keep redirection Rules first then keep rest of rules.
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php/?$ %{REQUEST_FILENAME}.php [QSA,L]
##Adding new rule here for non-existing pages here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?$1 [QSA,L]
非常感谢,这对我来说很有效,我认为这对所有需要这种规则的人来说都是一个很好的解决方案。