Forum Moderators: phranque

Message Too Old, No Replies

301 redirect help

301 redirect help

         

rmetfd

9:00 am on Mar 5, 2013 (gmt 0)

10+ Year Member



Hi

I've recently set up a word press website and need to redirect my old dynamic URL's to the new, cleaner, permalinks produced by Wordpress. I have about 30 links I need to redirect.

However, I haven't been able to get it to work. I've added the links im trying to redirect below, and have added the code that im using below that.



original url = mysite.com/index.aspx?id=28

new url = mysite.com/privacy-statement/

.htaccess file
---------------


RewriteCond %{QUERY_STRING} ^id=28$
RewriteRule ^index\.aspx$ http://www.mysite.com/privacy-statement/? [R=301,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

lucy24

9:23 am on Mar 5, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well, a RewriteRule won't be able to do much if you have not yet turned on the RewriteEngine :)

Ditch that <IfModule...> envelope. Either you have mod_rewrite or you don't. And if you don't, the only remedy is to get a new host.

Apart from the misplaced RewriteEngine On line, your new rules are in the right place. Redirects go before rewrites.

g1smd

9:54 am on Mar 5, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Presumably...

RewriteCond %{THE_REQUEST} [A-Z]{3,9}\ /(index\.aspx)?\?id=28\ HTTP/
RewriteRule ^(index\.aspx)?$ http://www.example.com/privacy-statement/? [R=301,L]


Beware the redirect fails if other parameters are in the request. Slightly more versatile...

RewriteCond %{THE_REQUEST} [A-Z]{3,9}\ /(index\.php)?\?
RewriteCond %{QUERY_STRING} (^|&)id=28(&|$)
RewriteRule ^(index\.aspx)?$ http://www.example.com/privacy-statement/? [R=301,L]


Dump the
IfModule
containers.

RewriteEngine On
should appear ONCE, at the beginning of the code.