Correct Syntax for 301 redirect: clarification needed

Discussion in 'Apache' started by Lever, Nov 23, 2006.

  1. #1
    I'm a bit rusty having not done 301 redirect for a couple of years and now I've got a major revamp needing numerous redirects... looking at some old htaccess files I've got the syntax:

    redirect 301 /oldpath http://www.domain.com/newpath
    Code (markup):
    Now obviously that is correct, it's just that I've currently got a file of redirects that looks like...

    redirect 301 /oldpath /newpath
    Code (markup):
    Now... will the redirect work without the http://www.domain.com prefix to the new path or not? I'm assuming it wouldn't but just wanted to clarify just in case.

    The redirects are going in the conf file which my ISP assures me is quicker for server response times than putting the redirects in an htaccess file.
     
    Lever, Nov 23, 2006 IP
    Weirfire likes this.
  2. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #2
    I might be wrong but should you not use something like

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^domain\.com [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

    That 1 there in particular changes domain.com into www.domain.com

    I've never seen the format you posted above.
     
    Weirfire, Nov 23, 2006 IP
  3. Lever

    Lever Deep Thought

    Messages:
    1,823
    Likes Received:
    94
    Best Answers:
    0
    Trophy Points:
    145
    #3
    Cheers dude, I've already got some rewrites running and they're great for generic changes but I've got a ton of individual pages/paths that need sorting so it's the old 301 redirect /oldpath /newpath route... the format is the same as I used when I shifted my blog from the back end of mantaworld.com to its own site. I simply used
    redirect 301 /foreverblueskies/2004/09/flying-slugs-are-go.html http://www.foreverblueskies.com/2004/09/flying-slugs-are-go.html
    Code (markup):
    and that worked a treat. There's still links being redirected from there 2 years later!

    Anyways, I need to know if, within the same domain, I need to prefix the htt protocol or not? I may just do it anyway to be safe :)
     
    Lever, Nov 23, 2006 IP
  4. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #4
    I'm not entirely sure if I'm honest. Send Nintendo a PM. He does this stuff all the time. Under all that crazy wackiness there is an intelligient individual. :)
     
    Weirfire, Nov 23, 2006 IP
  5. Lever

    Lever Deep Thought

    Messages:
    1,823
    Likes Received:
    94
    Best Answers:
    0
    Trophy Points:
    145
    #5
    OK, that got loaded in the conf file and Apache said the syntax was OK, so I'm sticking with that ;)
     
    Lever, Nov 25, 2006 IP