htaccess的WWW重定向搜索引擎友好的URL [英] htaccess www redirect for seo friendly url
本文介绍了htaccess的WWW重定向搜索引擎友好的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我想要的:
网址:http://www.domain.com/location/netherlands/amsterdam/amsterdam-airport
现在,如果有人打开这个网址加www我要的是,他应该被重定向到www。
记住这些搜索引擎友好的URL。我已经使用mod_rewrite为上述网址:
重写规则^位置/([^ /] +)/?([^ /] *)/?([^ /] *)/ $ /location.php?country = $ 1安培;城市2 = $&放大器;位置= $ 3 [L,QSA,NC]
现在,如果我使用任何htaccess的把戏做WWW重定向。这是我所得到的:
<$p$p><$c$c>http://www.domain.com/location.php?country=netherlands&city=amsterdam&location=amsterdam-airport如果您有任何问题,让我知道。谢谢!
解决方案
确认这个现有的规则之前有 WWW
规则:
的RewriteCond%{HTTP_HOST}!^ WWW \。 [NC]
重写规则^ HTTP://www.% {HTTP_HOST}%{REQUEST_URI} [R = 301,L]
重写规则^位置/([^ /] +)/?([^ /] *)/?([^ /] *)/ $ /location.php?country=$1&city=$2&location=$3 [L,QSA,NC]
另外,还要确保测试在不同的浏览器或测试前清除浏览器的缓存。
Here's what I want:
URL: http://www.domain.com/location/netherlands/amsterdam/amsterdam-airport
Now, what I want is if anyone open this url without www, he should get redirected to www.
Remember these are seo friendly url. I am already using MOD_REWRITE for the above url:
RewriteRule ^location/([^/]+)/?([^/]*)/?([^/]*)/?$ /location.php?country=$1&city=$2&location=$3 [L,QSA,NC]
Now if I do www redirect using any htaccess tricks. This is what I get:
http://www.domain.com/location.php?country=netherlands&city=amsterdam&location=amsterdam-airport
If you have any questions, let me know. Thanks!
解决方案
Make sure to have www
rule before this existing rule:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^location/([^/]+)/?([^/]*)/?([^/]*)/?$ /location.php?country=$1&city=$2&location=$3 [L,QSA,NC]
Also make sure to test in a different browser or clear your browser cache before testing.
这篇关于htaccess的WWW重定向搜索引擎友好的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文