htaccess的重写规则,旧的URL到新 [英] htaccess rewrite rule, old URL to new

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

问题描述

帮助老乡了一点,所以人。

我目前所面对的(基于一些code我用不同类型的URL)。

我要第一个URL重定向到第二,与事后没有包括查询字符串

这是我迄今。

 重写规则^(page.php?ID = missionstatement +)/ $ http://example.com/why/mission-statement [R = 301,L]
重写规则^(page.php?ID = OFSTED +)/ $ http://example.com/how/ofsted-report [R = 301,L]
重写规则^(page.php?ID = governingbody +)/ $ http://example.com/governors [R = 301,L]
 

解决方案

下面是规则(​​将重定向1网址):

 的RewriteCond%{QUERY_STRING} ^ n =什么
重写规则^页\ .PHP $ HTTP://%{HTTP_HOST} /如何/不知何故? [R = 301,L]
 

  1. 该规则旨在放置在.htaccess在网站根目录。如果放在其他地方的一些小的调整可能是必需的。

  2. 我已经使用%{HTTP_HOST} - 这将重定向到同一个域中请求的URL。如果域名已经是不同的,通过精确的域名替换它。

  3. 在新的URL年底将摆脱现有的查询字符串。

A bit of help fellow SO people.

What I have at the moment (based on some code I used for a different type of URL).

I want the first URL to redirect to the second, with no query string included afterwards

This is what I have to so far.

RewriteRule ^(page.php?id=missionstatement+)/?$ http://example.com/why/mission-statement [R=301,L]
RewriteRule ^(page.php?id=ofsted+)/?$ http://example.com/how/ofsted-report [R=301,L]
RewriteRule ^(page.php?id=governingbody+)/?$ http://example.com/governors [R=301,L]

解决方案

Here is the rule (will redirect 1 URL):

RewriteCond %{QUERY_STRING} ^id=whatever
RewriteRule ^page\.php$ http://%{HTTP_HOST}/how/somehow? [R=301,L]

  1. This rule intended to be placed in .htaccess in website root folder. If placed elsewhere some small tweaking may be required.

  2. I have used %{HTTP_HOST} -- this will redirect to the same domain as requested URL. If domain name has to be different, replace it by exact domain name.

  3. The ? at the end of new URL will get rid of existing query string.

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

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