开发者

htaccess rewrite rule, old URL to new

开发者 https://www.devze.com 2023-04-09 10:36 出处:网络
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).

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.


Ahoy!

Give this a whirl:

#check mod_rewrite is enabled
<IfModule mod_rewrite.c>

#enable mod rewrite
RewriteEngine On

#set working directory
RewriteBase /

#force trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [R=301,L]

#bootstrap index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page.php\?id=(.*)$ http://www.willans.com/page.php/$1 [R=310,L]

#end mod rewrite check
</IfModule>

It's been a while since i've done any web dev, but that should be a push in the right direction at least ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消