问题虽然从非WWW URL重定向到WWW URL
问题描述:
嗨在我们的网站上,我们遇到了一个问题,比如我们在没有WWW的情况下输入url等。 example.com/xyz
在这种情况下,后重定向它转换成www.example.com/?url=xyz
但应重定向到只是想:www.example.com/xyz
问题虽然从非WWW URL重定向到WWW URL
所以我们得到额外?url= in URL
我们使用的代码为重定向非WWW网址到www我们htaccess文件。在htaccess文件代码重定向:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
我们也试过这个代码,但不工作:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
</IfModule>
答
尝试把你的重定向规则前的路由规则:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
谢谢@JOnLin的答复,但它不解决我的问题仍然是问题是相同的吗?url = URL中即将到来 – Ankit 2014-10-06 16:31:29
@Ankit你清除了浏览器的缓存吗? – 2014-10-06 16:31:54
我已经检查了删除所有缓存后,即使在两个浏览器中检查。这个问题只在我尝试打开除example.com之外的其他主页时才会出现,如果我只为example.com尝试,它会重定向到www.example.com – Ankit 2014-10-06 16:43:07