mod_rewrite的设置子域和目录为GET变量 [英] Mod_Rewrite setting subdomain and directory to GET variable
问题描述
我编程,我想成为多语种网站,独立的语言应该是通过子域accessable,例如en.example.com,de.example.com等。
此外,我已经有一个重写设置目录的GET变量,改变example.com/name到example.com/index.php?page=name~~V。
不管是什么我想我找不到任何可能性妥善两者结合起来codeS,我需要这些各自的问题来使用。每一个在自己的作品中,我只需要一个方法既结合起来,使en.example.com/name将被重写,以example.com/index.php?page=name&lang=en~~V
我用什么目录GET变量
重写规则^ /?(\ W *)/ $的index.php?网页= $ 1 [L]
我发现的子域GET变量
的RewriteCond%{HTTP_HOST}!^ WWW \。
的RewriteCond%{REQUEST_URI}!指数\ .PHP
的RewriteCond%{HTTP_HOST} ^(。+?)\。例如\ .COM $
重写规则。* /index.php?lang=%1 [L]
您只需要结合你2规则
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^((?!万维网\。)[^。] +)\。例如\ .COM $
的RewriteCond%{REQUEST_URI}!^ /指数\ .PHP $ [NC]
重写规则^(。*)$ /index.php?page=$1&lang=%1 [L]
I programmed a website that I want to be multilingual, the separate languages should be accessable via subdomain, for example en.example.com, de.example.com and so on.
Furthermore I already have a rewrite to set a "directory" as GET variable, that changes example.com/name to example.com/index.php?page=name.
No matter what I tried I find no possibilities to properly combine the two codes I need to use with these respective problems. Each in it's own works, I only need a method to combine both, so that en.example.com/name will be rewritten to example.com/index.php?page=name&lang=en
What I use for directories to GET variables
RewriteRule ^/?(\w*)/?$ index.php?page=$1 [L]
What I found for subdomains to GET variables
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{REQUEST_URI} !index\.php
RewriteCond %{HTTP_HOST} ^(.+?)\.example\.com$
RewriteRule .* /index.php?lang=%1 [L]
You just have to combine your 2 rules
RewriteEngine On
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.example\.com$
RewriteCond %{REQUEST_URI} !^/index\.php$ [NC]
RewriteRule ^(.*)$ /index.php?page=$1&lang=%1 [L]
这篇关于mod_rewrite的设置子域和目录为GET变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!