的.htaccess URL重写后重定向旧的网页网址 [英] Redirect old page url after .htaccess url rewriting

查看:331
本文介绍了的.htaccess URL重写后重定向旧的网页网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经rewrited我的网址同htaccess的,现在我想重定向旧的URL的新的,但我不能弄清楚如何做到这一点毕竟。

I have rewrited my url's with htaccess and now I want to redirect the old url's to the new ones, but I can't figure it out how to do it after all.

这是我的重定向规则中使用:

This is my redirect rule used:

RewriteRule ^page/([^/]*)/$ /page.php?name=$1 [L]

旧的URL的是这样的:?page.php名=页名

The old url's look like this: page.php?name=page-name

新的URL的是这样的:/页/页名/

The new url's look like this: /page/page-name/

推荐答案

这就是当你想重定向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

这篇关于的.htaccess URL重写后重定向旧的网页网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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