I want two languages on my website - one french-specific website, and one in english for broader purposes (and no automatic translation). For maintenance reasons, I'd like to not duplicate images and CSS, ... I also set up subdomains for language variants - for now both point to the www folder of my domain.

So I have two "index.htm" and "index_fr.htm" files, and a "fr" subdomain.

I've read up a bit about htaccess, and I'd like to set one up so that DirectoryIndex index_fr.htm is triggered when accessed through the subdomain.

Is it feasible? does it make sense? and how?

  • Where is the DocumentRoot set for the subdomain? Is it served out of its own directory or out of the same? – Stephen Ostermiller Apr 21 '20 at 15:01
  • I'm a noob for this kind of stuff so please bear with me :/ First, it is not my own server, it is a webhosting (OVH). So the urls are already redirects. Both the www subdomain and the fr subdomain point to the www folder. So I'd say the DocumentRoot is the www folder. If you refer to a specific file called DocumentRoot, no idea where it is and I'd think it is not accessible by me. – luneart Apr 21 '20 at 15:08
  • DocumentRoot is an Apache directive (and so is DirectoryIndex). DocumentRoot controls which directory serves the files for a virtual host (usually a domain or subdomain). httpd.apache.org/docs/2.4/mod/core.html#documentroot On shared hosting you may not have a lot of control over that. It is common to have subdomains point to subfolders of the main DocumentRoot and that comes with its own set of problems. It sounds like your host set the DocumentRoot to the same directory for both your main domain and subdomain. Do you know if you can change that? – Stephen Ostermiller Apr 21 '20 at 15:12
  • I can. I set up the subdomain, and in doing so I chose the directory it points to. At first I tried having it pointing to a fr/ subfolder (with index.htm in french in it), but then it couldn't read my css which was then one level above... – luneart Apr 21 '20 at 15:17
  • to keep it simple, what I want is more like a hidden redirect of the subdomain url to that particular html file – luneart Apr 21 '20 at 15:20

I don't see as you necessarily need to change the DocumentRoot of the subdomain (as discussed in comments), since you want to "share images and CSS" between language versions.

However, changing the DirectoryIndex is probably not what you want to do either.

Instead, use mod_rewrite to internally rewrite the request to /index_fr.htm when requesting the document root of the subdomain.

For example, in your root .htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^fr\.example\.com [NC]
RewriteRule ^$ index_fr.htm [L]

This is essentially the equivalent of conditionally setting DirectoryIndex.

If you request https://fr.example.com/ then you'll be internally redirected to /index_fr.htm. Otherwise the normal DirectroryIndex will be served.

However, it's not clear how you want to handle requests of the form https://fr.example.com/foo? The above directive does not cover that.

  • 1
    perfect, thank you! for your question, I haven't thought about that...because it's a single-page website, and instead of having fr.example.com/foo I have fr.example.com#foo so it works :) – luneart Apr 23 '20 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.