How do I redirect old ugly ulrs to nice urls

て烟熏妆下的殇ゞ 提交于 2019-12-25 06:47:03

问题


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

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