Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Redirect to new page if old page not available

    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 :
    Code:
    RewriteEngine on
    RewriteRule ^(.*)$ blog/$1
    But, i redirects all pages...

    Thanks,

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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:
    Code:
    RedirectMatch /2007(.*) blog/2007$1
    &c for other years.

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I used this :
    Code:
    RedirectMatch permanent /2007(.*) blog/2007$1
    But it gives me a "500 Internal Error"...

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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...
    Code:
    RedirectMatch permanent /2007(.*) http://www.example.com/blog/2007$1

  • #5
    New Coder
    Join Date
    Jul 2006
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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.
    Code:
    RedirectMatch permanent ^/2007(.*) http://www.example.com/blog/2007$1

  • Users who have thanked tomws for this post:

    .Darkman (10-23-2008)

  • #7
    New Coder
    Join Date
    Jul 2006
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Code:
    RewriteRule ^2007(.*)$ blog/2007$1
    With this, redirect is successful.. But, am not able to do 301 redirect...

  • #8
    New Coder
    Join Date
    Jul 2006
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tomws View Post
    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.
    Code:
    RedirectMatch permanent ^/2007(.*) http://www.example.com/blog/2007$1
    That worked perfectly Thanks...

  • #9
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •