问题
I am trying to implement rewrite rules in my htaccess file but I am having difficulty implementing my specific requirements. My mission is two-fold -
- re-write ugly urls to friendly urls.
- re-direct ugly urls to friendly urls.
To be specific - I would like Anyone visiting http://mywebsite.com/?section=abstract to be redirected to http://mywebsite.com/gallery/abstract
And then internally the url http://mywebsite.com/gallery/abstract is written back to http://mywebsite.com/?section=abstract (but the user still sees the friendly url)
I have been able to get the latter bit working...
RewriteRule ^gallery/([^/\.]+)$ /?section=$1 [L]
But I don't know how to also redirect old/ugly urls to the nice ones.
回答1:
I have decided to implement the redirect in PHP....
If(strpos($_SERVER['REQUEST_URI'],"?section=")){
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://$_SERVER[HTTP_HOST]/gallery/$_GET[section]");
}
来源:https://stackoverflow.com/questions/16201609/how-do-i-redirect-old-ugly-ulrs-to-nice-urls