I need help setting up URL redirect files

Discussion in 'Apache' started by LawnchairLarry, Jul 5, 2008.

  1. #1
    I've browsed the extensive 301 redirect FAQ thread of this branch and half a dozen other pages, but still have trouble setting up a proper .htaccess file on my domains. Your help is greatly appreciated!
    I have two domains with a multilingual website located on one of them and I would like to permanently redirect all requests from the first domain to the English language homepage on the second domain. This should include a permanent redirect from the non-www of both domains and the www-version of the first domain to the www-version of the second domain and the location of the document that's shown when a file is not found (error 404).
    Since both domain names include the name of a city, you may expect people to use capitals when typing in the URL. Would that be a problem? I've read that one should use [NC] for non-case-sensitive URLs here, but I'm not quite certain how and where to. I've seen a few sample 301 redirects in the FAQ thread with and others without the two lines starting with "Options". What is the purpose of these two lines? Should I definitely include those two lines or can they be omitted under certain circumstances? I've come up with the following code. Are these alright?

    For the .htaccess file on domain 1:

    Options +Indexes
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^[COLOR="Blue"]domain1[/COLOR]\.tld$ [COLOR="Magenta"][NC][/COLOR]
    RewriteRule (.*) http://www.[COLOR="Red"]domain2[/COLOR].tld/$1 [R=301,L]
    RewriteCond %{HTTP_HOST} !^www\.[COLOR="Blue"]domain1[/COLOR]\.tld$ [COLOR="Magenta"][NC][/COLOR]
    RewriteRule (.*) http://www.[COLOR="Red"]domain2[/COLOR].tld/$1 [R=301,L]
    Code (markup):
    For the .htaccess file on domain 2:

    Options +Indexes
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^[COLOR="Red"]domain2[/COLOR]\.tld$ [COLOR="Magenta"][NC][/COLOR]
    RewriteRule (.*) http://www.[COLOR="Red"]domain2[/COLOR].tld/$1 [R=301,L]
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index-en\.htm\ HTTP/
    RewriteRule http://www.[COLOR="Red"]domain2[/COLOR].tld/ http://www.[COLOR="Red"]domain2[/COLOR].tld/index-en.htm [R=301,L]
    
    ErrorDocument 404 http://www.[COLOR="Red"]domain2[/COLOR].tld/error404.htm
    Code (markup):
     
    LawnchairLarry, Jul 5, 2008 IP