htaccess www redirect for seo friendly url

非 Y 不嫁゛ 提交于 2019-12-24 07:14:30

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/18734904/htaccess-www-redirect-for-seo-friendly-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!