htaccess rewrite for language subdomains

Server Fault Asked by FFish on July 28, 2020

I need to point subdomains like 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


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)$
        # 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

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 CNAME
while CNAME

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

2 Answers

You wrote:

In my DNS list I see that CNAME while CNAME

Maybe the problem is about your DNS configuration.

My own DNS configuration is something like:

$TTL 86400
@   IN SOA (2011111300 86400 3600 3600000 86400)
            IN  NS 
            IN  NS 
            IN  A 
*           IN  CNAME 

This means "if you type or whatever behind i.e. or go to the server at the adress

If I change the adress to a new one for example, this will work and as soon as you'll type or any other stuff (like explained before) it will go to Everything will work smoothlessly without touching any .htaccess file.

So try to apply the same DNS configuration on your site.

Answered by Olivier Pons on July 28, 2020

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?

Answered by Ladadadada on July 28, 2020

Add your own answers!

Related Questions

How to install company proxy certificate

1  Asked on January 9, 2021 by chandima-jayawickrema


Windows server 2019 RRAS slow download speed

0  Asked on January 9, 2021 by selfishcrawler


Allow download of pdf files only in .htacces file

0  Asked on January 9, 2021 by user2033464


Freeradius LDAP through AP

1  Asked on January 9, 2021 by smok


NFS access from multiple networks

1  Asked on January 7, 2021


Nginx+gunicorn 404

1  Asked on January 6, 2021 by vassily


Docker swarm, all containers get restarted

1  Asked on January 6, 2021 by saabeilin


Error when update Sugarcrm CE via Admin->Upgrade

0  Asked on January 5, 2021 by ashish-kumar-dubeyitho-noidain


Is deploying .NET Framework 3.5 possible in WSUS?

4  Asked on January 5, 2021 by thecleaner


How to know if the server application is listening on ipv6

2  Asked on January 5, 2021 by lapinkoira


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP