我如何将旧的丑陋的URL重定向到漂亮的URL [英] How do I redirect old ugly ulrs to nice urls

查看:67
本文介绍了我如何将旧的丑陋的URL重定向到漂亮的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在htaccess文件中实现重写规则,但是在实现特定要求方面遇到困难.我的任务是双重的-

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 -

  • 重新-丑陋的URL到友好的URL.
  • re- 直接丑陋的URL转换为友好的URL.
  • re-write ugly urls to friendly urls.
  • re-direct ugly urls to friendly urls.

具体来说-我希望任何人访问 http://mywebsite.com/?section=abstract重定向 http://mywebsite.com/gallery/abstract

To be specific - I would like Anyone visiting http://mywebsite.com/?section=abstract to be redirected to http://mywebsite.com/gallery/abstract

然后将内部 http://mywebsite.com/gallery/abstract 内部写回 http://mywebsite.com/?section=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.

推荐答案

我决定在PHP中实现重定向....

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]"); 

}

这篇关于我如何将旧的丑陋的URL重定向到漂亮的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆