AnswerBun.com

htaccess rewrite for language subdomains

Server Fault Asked by FFish on July 28, 2020

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.

2 Answers

You wrote:

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

Maybe the problem is about your DNS configuration.

My own DNS configuration is something like:

$TTL 86400
@   IN SOA dnsxx.ovh.net. tech.ovh.net. (2011111300 86400 3600 3600000 86400)
            IN  NS     dnsxx.ovh.net. 
            IN  NS     nsxx.ovh.net. 
            IN  A      123.123.123.123 
*           IN  CNAME  papdevis.fr. 

This means "if you type papdevis.fr or whatever behind i.e. www.papdevis.fr or olivier.papdevis.fr go to the server at the adress 123.123.123.123.

If I change the adress 123.123.123.123 to a new one for example 234.234.234.234, this will work and as soon as you'll type papdevis.fr or any other stuff (like explained before) it will go to 234.234.234.234. 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 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP