0

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.

FFish
  • 101
  • 1
  • Thank you for using my answer here http://stackoverflow.com/questions/9531002/htaccess-rewrite-for-language-subdomains/9635159#9635159, this is a great reward that what I write isn't useless ;) – Olivier Pons Mar 13 '12 at 08:28

2 Answers2

0

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?

Ladadadada
  • 26,337
  • 7
  • 59
  • 90
  • hi, no I can't. No symlinks either, I tried that allready making them with PHP's `symlink()` function but it doesn't work. – FFish Mar 10 '12 at 13:56
  • In that case, I think you might be best off going for a subdirectory such as `/es/` or a query string such as `?lang=es` instead of subdomains. If you want to be clever, you can use the client's `Accept-Language` header to choose the best language for them. – Ladadadada Mar 10 '12 at 14:28
  • That's what I have right now, with a `?locale=es_ES` var, but I need to solution with the subdomains for SEO and Analytics. `/es/` directories are too difficult to implement right now. – FFish Mar 10 '12 at 18:27
0

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.

Olivier Pons
  • 622
  • 1
  • 5
  • 22