301 Redirects mod_rewrite

Discussion in 'Apache' started by qlmarketing, Feb 8, 2011.

  1. #1
    Hi i am a complete noob when it comes to apache and really would appreciate any help i can get.

    I am about to move a site from example.com to example.com.au it has 1600 pages indexed in google and was hoping not to have to write a rule for each page rather appened the .au to any request for that domain simmilar to a www.

    is it possible to do somthing simmiarl to the code below to add a .au to the domain name

    thanks in advanced
    Cheers
    Nick

    # For sites running on a port other than 80
    RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
    RewriteCond %{HTTP_HOST}   !^$
    RewriteCond %{SERVER_PORT} !^80$
    RewriteRule ^/(.*)         http://www.example.com:%{SERVER_PORT}/$1 [L,R]
    
    # And for a site running on port 80
    RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
    RewriteCond %{HTTP_HOST}   !^$
    RewriteRule ^/(.*)         http://www.example.com/$1 [L,R]
    Code (markup):
     
    qlmarketing, Feb 8, 2011 IP
  2. clau

    clau Guest

    Messages:
    57
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi Nick,

    Here is a .htaccess file that does what you want.

    
    AddHandler cgi-script .cgi
    #AddType application/x-httpd-cgi .cgi .pl
    #Options +Indexes +ExecCGI
    #DirectoryIndex index.cgi
    #AllowOverride Limit FileInfo Indexes
    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.example.com$
    RewriteRule ^(.*)$ "http\:\/\/www\.example\.com\.au\/$1" [R=301,L]
    
    Code (markup):
    This also redirects the non-www to www but if you don't want this you can remove the [OR] RewriteCond %{HTTP_HOST} ^www.example.com$ part
     
    clau, Feb 8, 2011 IP
  3. qlmarketing

    qlmarketing Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi Clau,

    Much appreciated thank you for your response
     
    qlmarketing, Feb 8, 2011 IP