问题
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