Results 1 to 6 of 6

Thread: 301 permanent redirect

  1. #1
    Join Date
    Nov 2008
    Location
    Ireland
    Posts
    128

    Default 301 permanent redirect

    I am trying to redirect http:// to http://www. as google has split my page rank between the two versions.

    I have tried using the following in htaccess but it does not seem to work

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www.ownerdirectspain.com$ [NC]
    RewriteRule ^(.*)$ http://www.ownerdirectspain.com/$1 [L,R=301]

    is there a flaw with this code?

  2. #2
    Join Date
    Jul 2003
    Location
    California
    Age
    43
    Posts
    4,229

    Default Re: 301 permanent redirect

    Your condition is for the domain with WWW to be rewritten to the rule of your domain with WWW. Basically, the rewrite rule would do nothing. You would want the rewrite rule to be the following to rewrite domain.com to www.domain.com:

    RewriteCond %{HTTP_HOST} ^ownerdirectspain.com$ [NC,OR]
    RewriteRule ^(.*)$ http://www.ownerdirectspain.com/$1 [R=301,L]

    I'm pretty sure that will do it but its late so I may have screwed up, basically the condition should be what you want to change FROM and the rule is what you want to change TO

    Also, if you are using OR 3 your custom rewrites in the .htaccess must come before the OR rewite rules or they won't work
    Open-Realty 2 Documentation

    ~The Difference Between an ORDEAL and an ADVENTURE is ATTITUDE~

  3. #3
    Join Date
    Nov 2008
    Location
    Ireland
    Posts
    128

    Default Re: 301 permanent redirect

    Thanks Mick
    Unfortunately the revised code did not work
    RewriteCond %{HTTP_HOST} ^ownerdirectspain.com$ [NC,OR]
    RewriteRule ^(.*)$ http://www.ownerdirectspain.com/$1 [R=301,L]

    However, I experimented and this version appears to work
    RewriteCond %{HTTP_HOST} ^ownerdirectspain.com$
    RewriteRule ^(.*)$ http://www.ownerdirectspain.com/$1 [R=301,L]

    I took out the [NC,OR] one - because I didnt know what it does and two - because it worked without it?

    Thanks for the help

  4. #4
    Join Date
    Nov 2008
    Location
    Ireland
    Posts
    128

    Default Re: 301 permanent redirect

    Quote Originally Posted by OwnerDirectSpain View Post
    Thanks Mick
    Unfortunately the revised code did not work
    RewriteCond %{HTTP_HOST} ^ownerdirectspain.com$ [NC,OR]
    RewriteRule ^(.*)$ http://www.ownerdirectspain.com/$1 [R=301,L]

    However, I experimented and this version appears to work
    RewriteCond %{HTTP_HOST} ^ownerdirectspain.com$
    RewriteRule ^(.*)$ http://www.ownerdirectspain.com/$1 [R=301,L]

    I took out the [NC,OR] one - because I didnt know what it does and two - because it worked without it?

    Thanks for the help
    ps to last post - anyone know if there is a major reason to have the [NC,OR] at the end of the rewrite condition?

  5. #5
    Join Date
    Jul 2003
    Location
    California
    Age
    43
    Posts
    4,229

    Default Re: 301 permanent redirect

    Sorry, I'd done a quick cut/paste from my rewrite rules and forgot to take out the OR

    OR is for multiple conditions for a single rewrite rule, for example, to rewrite multiple domains to a single domain name which is what I use it for.

    NC you will want in there at the least as it tells apache to ignore the case of the letters. Without the NC in there... the condition will not rewrite OwnerdirectSpain.com since it doesn't match the rewrite rule's characters exactly.
    Open-Realty 2 Documentation

    ~The Difference Between an ORDEAL and an ADVENTURE is ATTITUDE~

  6. #6
    Join Date
    Nov 2008
    Location
    Ireland
    Posts
    128

    Default Re: 301 permanent redirect

    Quote Originally Posted by Mick View Post
    Sorry, I'd done a quick cut/paste from my rewrite rules and forgot to take out the OR

    OR is for multiple conditions for a single rewrite rule, for example, to rewrite multiple domains to a single domain name which is what I use it for.

    NC you will want in there at the least as it tells apache to ignore the case of the letters. Without the NC in there... the condition will not rewrite OwnerdirectSpain.com since it doesn't match the rewrite rule's characters exactly.
    Thanks Mick i've implemented that change.

Similar Threads

  1. url redirect
    By eXinRex in forum General Help (CLOSED)
    Replies: 5
    Last Post: 11-16-2007, 10:43 PM
  2. logout redirect
    By 2let2sell2buy in forum Installation/Configuration Help (CLOSED)
    Replies: 1
    Last Post: 10-06-2007, 04:06 PM
  3. How to: htaccess permanent redirect
    By bit in forum General Help (CLOSED)
    Replies: 12
    Last Post: 10-02-2007, 10:29 PM
  4. Replies: 20
    Last Post: 03-11-2007, 01:45 PM
  5. Changing temporay URL to permanent URL
    By patdpoo in forum Installation/Configuration Help (CLOSED)
    Replies: 4
    Last Post: 05-26-2006, 03:58 PM

Tags for this Thread

Bookmarks

Posting Permissions

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