homepage Welcome to WebmasterWorld Guest from 54.227.34.0
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
301 redirect help
301 redirect help
rmetfd



 
Msg#: 4551290 posted 9:00 am on Mar 5, 2013 (gmt 0)

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

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4551290 posted 9:23 am on Mar 5, 2013 (gmt 0)

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

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4551290 posted 9:54 am on Mar 5, 2013 (gmt 0)

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.
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved