Forum Moderators: phranque

Message Too Old, No Replies

Need RewriteRule to redirect my blog to another

         

ElMobd3

10:07 pm on Sep 3, 2010 (gmt 0)

10+ Year Member



Hi all,
I have a blog which its url is ***.com/link/
It's a WordPress.
then I changed the url to ***.com/blog/ so I need a RewriteRule to redirect links like that:
***.com/link/?p=21 to ***.com/blog/?p=21

I tried that RewriteRule
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(?p=[0-9]+)$ mysite.com/blog/?p=$1
but I get an error.
I hope you can help me.

g1smd

10:46 pm on Sep 3, 2010 (gmt 0)

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



That's a rewrite.

You'll need a redirect. The target will need the protocol and domain name added. You'll need the [R=301,L] flags.

RewriteRule cannot see query string data, so you'll need a preceding RewriteCond looking at QUERY_STRING.

RewriteRule will need to look for a request containing "link" or "link/index.php" for best operation.

ElMobd3

1:38 am on Sep 4, 2010 (gmt 0)

10+ Year Member



Thanks for your reply.
Sorry I'm not good in writing rewriteRules and now I have another content at "link" so I need a specific rewrite or RewriteRule that enables URLs like "***.com/link/?p=21" redirect to "***.com/blog/?p=21" the 21 here meaning all numbers.

jdMorgan

2:49 pm on Sep 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Following g1smd's advice above, and consulting the mod_rewrite documentation, you'd get something like this:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^p=[0-9]+)$
RewriteRule ^link/?$ http://mysite.com/blog/?p=%1

Please see the Apache mod_rewrite documentation and the regular-expressions tutorial cited in our Apache Forum Charter for more information, as well as tips on how to get the most from this forum.

Jim

ElMobd3

11:04 pm on Sep 4, 2010 (gmt 0)

10+ Year Member



Great I do that.
Thanks a lot to g1smd and sure jdMorgan :D.