Forum Moderators: phranque

Message Too Old, No Replies

B2evolution to Wordpress - Need help redirecting tags

B2evolution to wordpress redirection in .htaccess

         

Rstigers

3:55 am on Dec 31, 2010 (gmt 0)

10+ Year Member



I had an old B2evolution blog I converted to Wordpress and need help with the redirection in the .htaccess file...

I am currently using about 60 redirect 301s similar to the one below, but there are 100's more tags that are not being redirected properly...

redirect 301 /blog/blog5.php/tag/virtual+sound+illusion: http://web420.com/blogs/tag/virtual-sound-illusion/




I need help making a rewrite rule to redirect from pages like:

web420.com/blog/blog5.php/tag/virtual+sound+illusion:
to
web420.com/blogs/tag/virtual-sound-illusion/

the new style has a different location, "-" instead of "+" between words, and a "/" rather than a ":" at the end...

I have already tried searching the internet and modifying some rewrite rules I found, but I couldn't get them to do what I want.
If anyone can help me with this rewrite rule I would be grateful.



thanks!

g1smd

7:04 pm on Dec 31, 2010 (gmt 0)

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



There's more than one way to do this.

One way is having hundreds of
Redirect
lines.

Another is to use the power of mod_rewrite and use
RewriteRule
instead. In this way, using pattern matching, many rules invoking redirects can be condensed to just a few. This method can be used when there is a simple relationship between the old and new URLs, specifically when URL parts in the request can be captured and reused in the target URL.

Another way to proceed would be to rewrite all requests so that they are handled by an internal PHP script which then sends the correct 301 redirect HTTP headers. This method is needed when there is no "connection" between the words in the original URL request and those in the target URL.

jdMorgan

6:11 pm on Jan 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The .htaccess solutions are fairy simple, but since there is no support for recursion, you will need one rule for each possible number of plus signs. Here's an example for up to five:

RedirectMatch 301 ^/blog/blog5\.php/tag/([^+]+)\+([^+]+)\+([^+]+)\+([^+]+)\+([^+:]+):$ http://example.com/blogs/tag/$1-$2-$3-$4-$5/
RedirectMatch 301 ^/blog/blog5\.php/tag/([^+]+)\+([^+]+)\+([^+]+)\+([^+:]+):$ http://example.com/blogs/tag/$1-$2-$3-$4/
RedirectMatch 301 ^/blog/blog5\.php/tag/([^+]+)\+([^+]+)\+([^+:]+):$ http://example.com/blogs/tag/$1-$2-$3/
RedirectMatch 301 ^/blog/blog5\.php/tag/([^+]+)\+([^+:]+):$ http://example.com/blogs/tag/$1-$2/
RedirectMatch 301 ^/blog/blog5\.php/tag/([^+:]+):$ http://example.com/blogs/tag/$1/

Alternately, using mod_rewrite:

RewriteRule ^blog/blog5\.php/tag/([^+]+)\+([^+]+)\+([^+]+)\+([^+]+)\+([^+:]+):$ http://example.com/blogs/tag/$1-$2-$3-$4-$5/ [R=301,L]
RewriteRule ^blog/blog5\.php/tag/([^+]+)\+([^+]+)\+([^+]+)\+([^+:]+):$ http://example.com/blogs/tag/$1-$2-$3-$4/ [R=301,L]
RewriteRule ^blog/blog5\.php/tag/([^+]+)\+([^+]+)\+([^+:]+):$ http://example.com/blogs/tag/$1-$2-$3/ [R=301,L]
RewriteRule ^blog/blog5\.php/tag/([^+]+)\+([^+:]+):$ http://example.com/blogs/tag/$1-$2/ [R=301,L]
RewriteRule ^blog/blog5\.php/tag/([^+:]+):$ http://example.com/blogs/tag/$1/ [R=301,L]

I provided the mod_alias RedirectMatch directive example because it is most similar to the Redirect directive you already tried. However, be aware that if you also use mod_rewrite --or if you might do so in the future-- then you should use the mod_rewrite version instead. This is because mixing mod_alias redirects and mod_rewrite directives can cause unexpected problems due to unknown module execution order (which might change if your server gets upgraded, leading to a sudden and mysterious redirection failures which may well result in search ranking loss).

Since you are using WordPress which includes its own mod_rewrite code, you will have to use the mod_rewrite code above. Also, be very sure to put these new redirect RewriteRules ahead of the WP internal rewriting code and ahead of your domain canonicalization redirect as well (if you have one). See this thread [webmasterworld.com] in our Apache Forum Library for more info.

For discussion of a simple way to modify the WP rewrite code for a potentially-dramatic increase in server performance, see this thread [webmasterworld.com] in our Apache Forum Library.

Jim