2 domain name (EN / FR) 1 FTP redirect

I have a problem with my .htaccess file.

I have two domain names associated with the same FTP server. One domain name is in English and the other is in French.

For now

  • if users wrote english-hostname.com -> it links to index.html (classic)
  • if user types french-hostname.com -> it also links to the same index.html

So, this is what I would like to have:

  • if users wrote english-hostname.com -> it links to index.html
  • if user types french-hostname.com -> he should link to Index-fr.html

Since I really don't want "index-fr.html" to appear in the URL, I created a subfolder called "fr" and I put the French index in it.

Here is my .htaccess file

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

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

      

I am clearly not familiar with these redirect / rewrite rules, every time I try to do something this code crashes my site (500 error ...)

Any idea please?

Thank!

Mill

+3


source to share


1 answer


Place each version in a dedicated folder for better organization. Then you need additional conditions to properly redirect your domains:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www.)?english-hostname.com$
RewriteCond %{REQUEST_URI} !^/en/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /en/$1

RewriteCond %{HTTP_HOST} ^(www.)?french-hostname.com$
RewriteCond %{REQUEST_URI} !^/fr/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /fr/$1

      



Be aware that http://english-hostname.com/fr/ is still available and back.

0


source







All Articles