Php 如何通过删除';www';in.htaccess
好的,我有一个基于PHP MVC的网站。首先,我想从我的域URL中删除“www”,如下所示:Php 如何通过删除';www';in.htaccess,php,.htaccess,mod-rewrite,redirect,model-view-controller,Php,.htaccess,Mod Rewrite,Redirect,Model View Controller,好的,我有一个基于PHP MVC的网站。首先,我想从我的域URL中删除“www”,如下所示: http://www.example.com/ -> http://example.com/ 我的.htaccess是: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ index.php?url=$1 [B] RewriteCo
http://www.example.com/ -> http://example.com/
我的.htaccess是:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [B]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,NC,L]
这工作正常,它从www重定向到非www。但当我请求时:
http://www.example.com/Controller/Method/
重定向到:
http://example.com/Controller/Method/?url=Controller%252fMethod%252f
它添加了查询字符串,这是我不想要的,而正确的查询字符串必须是:
http://example.com/Controller/Method/
有什么想法吗?您只需在重写规则的末尾添加一个
?
,即可在重定向时删除查询字符串
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [B]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI}? [R=301,NC,L]
问题仍然存在,仍然使用QueryString
http://example.com/Controller/Method/?url=Controller%252fMethod%252f
您需要清除浏览器缓存。301缓存了它。