问题
How can be this
http://some-url.com/?lang=en
rewritten to this:
http://en.some-url.com ???
via mod_rewrite?
回答1:
You could define all possible languagespecific subdomains as ServerAlias in the VirtualHost-configfile of some-url.com and add following rewriterule
RewriteEngine On
RewriteCond %{HTTP_HOST} ^some-url\.com$ [NC]
RewriteCond %{QUERY_STRING} lang=(.*)$
RewriteRule . http://%1.some-domain.com/? [R=301,L]
In your serverside script you can get the actual language by checking SERVER/CGI variable called HTTP_HOST (in php this would be $_SERVER['HTTP_HOST']
while in ColdFusion this would be #CGI.HTTP_HOST#
)
来源:https://stackoverflow.com/questions/10368298/apache-mod-rewrite-rule-as-subdomain