Forum Moderators: phranque
I'm running a quite large multi language web site. At the moment the language of the site is determined from the path of the URI. E.g. http://www.example.com/en/what/ever.html would show an English site.
.htaccess:
RewriteEngine on
RewriteRule ^([a-z][a-z])/?$?lang=$1 [L]
RewriteRule ^([a-z][a-z])/([a-z_]+)/?$?lang=$1&page=$2 [L]
RewriteRule ^([a-z][a-z])/([a-z_]+)/(.+).html?$?lang=$1&page=$2&part=$3 [L]
Now I'm looking to rewrite the .htaccess file to be able to pass the language parameter to sub domain level (wikipedia stylish). Such as [en.example.com...] I'm thinking it should be something like this, however it's not fully working out for me.
.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule (.*) ?lang=%1&theuri=$1 [L]
Any help would be much appreciated!
Jon
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^([a-z]{2})\.example\.com
RewriteRule ^([a-z_]+)/?$ /?lang=%1&page=$1 [L]
#
RewriteCond %{HTTP_HOST} ^([a-z]{2})\.example\.com
RewriteRule ^([a-z_]+)/([^/.]+)\.html?$ /?lang=%1&page=$1&part=$2 [L]
The same goes for the non-www and www version of your domain (and subdomains), and domains and subdomains with or without trailing dots or port numbers -- Redirect all non-canonical hostnames to the canonical hostname. For example, you might get a request for http://www.en.example.com.:80/somepage.html. That is a perfectly-valid request (try it with a real page name), but should be externally redirected to http://en.example.com/somepage.html before internally rewriting the request to your script.
Jim
Your rewrite code looks just as what I'm looking for. However it gives me a "500 Internal Server Error" and I'm pretty certain that my hosting company are to blame (I don't know if I'm allowed to mention them, they're one.com, any mods feel free to remove that if I'm breaking the TOS). I found this in their FAQ:
"To set up a sub-domain, you should add a directory to the root for your web hotel. There should be an index file in the directory."
So... I suppose they are messing with something similar at a lower level, supposedly httpd.conf. I'm not sure if I can override that.
I'M STUCK! :´-(
Jon
[edit: Getting 500, not 404 as previously stated. Sorry]
You must implement the new file structure so that the rewritten filepaths are valid. This includes any subdomain-to-filespace mapping needed to resolve the requested (and rewritten) URL to a file.
From your description, it sounds like you need to investigate the capabilities of your "control panel" and find out what options are available for mapping domains and/or subdomains into your account's filespace.
In order to use the code above, you'll need to map all subdomains to your original domain's filespace. This may or may not be possible with your particular control panel. If it isn't, then you won't be able to use that code, and instead will have to take a different approach -- possibly using *nix symlinks from the subdomains' filespaces back to the main domain's filespace, so that your script "appears" to exist in each of your subdomains' filespaces.
Jim
I suppose I would need a rule to match the main page of a certain sub domain.
Anyway that's not the problem at the moment. I will look closer at the different possible solutions you mentioned.
Thanks,
Jon