How to Route Various domain Aliases to Fetch their Own Folders with Own Webpage PHP Files?
imagine the root of a server where multiple aliases such as website.nl; website.de; etc. all direct to the root the root \httpdocs\ with this physical hosting:
httpdocs\...
httpdocs\holland\ # webpages in Dutch (home.php | contact.php | etc)
httpdocs\deutsch\ # webpages in English (home.php | contact.php | etc)
httpdocs\images\ # all multilingual webpages share the same images
httpdocs\js_css\ # all multilingual webpages share the same scripts/layout
httpdocs\.htaccess # here be a clean root, nothing else than .htaccess
Thus, only the webpages .php differ: the rest they all share the same! Now imagine that you want to configure .htacces via apache script to make "bridge the gap" if you will, between the root and the folder, making it possible to type this in browser and below water fetching开发者_如何学JAVA the right php webpage, but keeping the shorter url in the browser:
website.nl/home.php
website.de/home.php
(As opposed to seeing this in the browser: website.nl/holland/home.php | website.de/deutsch/home.php)
What apache script line will do such thing?
Thanks: Much appreciated!You need to have "mod_rewrite" installed in apache.
Assuming you do, place a .htaccess file in the root directory of that account
(probably:)
~/public_html/.htaccess
and then put this in that file
RewriteEngine on
RewriteCond %{HTTP_HOST} ^website.nl(.*)$ [OR]
RewriteCond %{HTTP_HOST} ^www.website.nl(.*)$
RewriteRule ^.*$ "http\:\/\/www\.website\.nl\/holland\/$1" [L,P]
And then repeat the rewrite condition for website.de
Basically that says, grab the section after the website.nl part, and paste it on the part after holland, but the "L,P" says to make that a silent redirect and keep the user on the same url as they entered with.
goodluck!
Assuming you have full control over the server configuration, I would tend to a setup without mod_rewrite. Instead I'd use two separate VirtualHost
s for each country site, and Alias
directives to map the shared directories. In an abridged version, something like this:
<VirtualHost website.nl>
DocumentRoot /httpdocs/holland
ServerName website.nl
Alias /images /httpdocs/images
Alias /js_css /httpdocs/js_css
</VirtualHost>
<VirtualHost website.de>
DocumentRoot /httpdocs/deutsch
ServerName website.de
Alias /images /httpdocs/images
Alias /js_css /httpdocs/js_css
</VirtualHost>
this lets you work freely in both languages, and add new resources and URLs without having to edit anything - only if a shared resource is added, you have to touch the Alias
directives and restart the server.
精彩评论