且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

的.htaccess URL重写后重定向旧的网页网址

更新时间:2023-09-12 08:37:16

这就是当你想重定向URL使用GET参数有点复杂了。

That's a bit complex when you want redirect an url with GET parameters.

下面是一个把戏做到这一点:

Here's a trick to do it :

RewriteRule ^page\.php$ %{QUERY_STRING} [C]
RewriteRule name=(.*) /page/$1/? [R=301,L]

解释相关:

  • 首先,您重定向 page.php?NAME =网​​页名称?NAME =网​​页名称
  • 然后,你问使用下面的规则造成这种结果(使用 [C] 标签)
  • 第三,你重定向页名,捞起用(。*)页/页名/
  • 最后绝招,如果你不把最后 ,您的查询字符串将被添加到你的结果,你就会有这样的网址:页/页名/?NAME =网​​页名称。使用一个无用的删除旧的GET参数。
  • First, you redirect page.php?name=page-name to ?name=page-name
  • Then, you ask using the following rule for this result (with [C] tag)
  • Third, you redirect page-name, picked with (.*) to page/page-name/
  • Last trick, if you don't put the last ?, your query string will be appended to your result and you'll have this kind of url : page/page-name/?name=page-name. Using an useless ? erase the old GET parameters.

找到一些信息,在这里:

Found some informations here :

  • Apache mod_rewrite doc
  • How to strip a query string