Htaccess rewrite for language subdomains

.htaccesslanguagesmod-rewritesubdomain

I need to point subdomains like es.domain.com to /public/www/index.php
The problem is my host does NOT provide me to set a path, I can only set up the subdomains for "local use", which creates the folders in the public directory

My structure is

/public/
/public/de/
/public/es/
/public/it/
/public/www/index.php

My host told me to use .htaccess files inside the sub domain folders.

I tried, for example in /public/es/ something like

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^(de|es|it)\.mydomain\.com$
        # Create an environment variable to remember the language:
    RewriteRule (.*) - [QSA,E=LANGUAGE:%1]
        # Now check if the LANGUAGE is empty (= doesn't exist)
    RewriteCond %{ENV:LANGUAGE} !^$
        # If so, create the default language (=es):
    RewriteRule (.*) - [QSA,E=LANGUAGE:es]
        # Change the root folder of the spanish language:
    RewriteCond %{ENV:LANGUAGE} ^es$
        # Change the root folder:
    RewriteRule ^/?$ /public/www/index.php
</IfModule>

But I am getting a 404 on this:
The requested URL /public/www/index.php was not found on this server.

In my DNS list I see that
es.domain.com CNAME onlinux-it.setupdns.net
while
www.domain.com CNAME domain.com

I tried also assigning
es.domain.com CNAME to domain.com
but that did not change anything.

Best Answer

The best way would be to change the DocumentRoot directive in your Apache config files for those sobdomains so that they all point to /public/www/ but I guess you can't do that.

I don't think there's any way to do what you are asking with a .htaccess file.

You could create a symlink instead of a folder so that:

/public/de/ -> /public/www/

Are you able to do that?

Related Topic