...

View Full Version : Redirect to new page if old page not available



.Darkman
10-23-2008, 05:35 AM
Hello Everybody,

I had my blog at http://gotchance.com/ and now i've moved this to http://gotchance.com/blog/

Now, since all links point to the old url, i'd like to redirect them to the new ones.. For eg. http://gotchance.com/2007/06/04/post-name to http://gotchance.com/blog/2007/06/04/post-name

At the same time, i have a new site at gotchance.com. I don't wanna redirect its pages. For eg, i now hav http://gotchance.com/index.htm and i don't want it to be redirected to http://gotchance.com/blog/index.htm

How do i do it ?
I used this :

RewriteEngine on
RewriteRule ^(.*)$ blog/$1
But, i redirects all pages...

Thanks,

tomws
10-23-2008, 06:52 AM
Yes, .* means anything, so it should redirect everything.

I might try a RedirectMatch with a 301 (moved permanently) status code. That'll help the search engines pick up the changes.
http://httpd.apache.org/docs/2.2/mod/mod_alias.html

Perhaps something like:
RedirectMatch /2007(.*) blog/2007$1 &c for other years.

.Darkman
10-23-2008, 09:17 AM
I used this :

RedirectMatch permanent /2007(.*) blog/2007$1
But it gives me a "500 Internal Error"...

tomws
10-23-2008, 05:07 PM
Hmm... I usually do this by trial and error since it's not an everyday task.

Now that I look at some of my own configs, shouldn't the target of the redirect be the full URL? Like this...

RedirectMatch permanent /2007(.*) http://www.example.com/blog/2007$1

.Darkman
10-23-2008, 06:13 PM
This again gives me an error from Firefox :

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

tomws
10-23-2008, 06:20 PM
Okay, that would suggest an infinite redirect, which I guess makes sense because /2007 also matches blog/2007. In that case, maybe we need the caret in front to mark the beginning of the path.

RedirectMatch permanent ^/2007(.*) http://www.example.com/blog/2007$1

.Darkman
10-23-2008, 06:21 PM
RewriteRule ^2007(.*)$ blog/2007$1
With this, redirect is successful.. But, am not able to do 301 redirect...

.Darkman
10-23-2008, 06:23 PM
Okay, that would suggest an infinite redirect, which I guess makes sense because /2007 also matches blog/2007. In that case, maybe we need the caret in front to mark the beginning of the path.

RedirectMatch permanent ^/2007(.*) http://www.example.com/blog/2007$1

That worked perfectly :) Thanks...

tomws
10-23-2008, 06:24 PM
NP. Sorry for the long process. As I said, I don't set those up everyday, so it takes some time to figure it out again when I do.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum