Apache mod_rewrite rule as subdomain

你离开我真会死。 提交于 2019-12-13 07:25:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!