2014-01-07 52 views
1

存在我想做某事像这一点,如果子域是网址:路线,只有当子域网址

http://example.com/     -> index.php 
http://hello.example.com/   -> profile.php?subdomain=hello 
http://whatever.example.com/  -> profile.php?subdomain=whatever 
http://example.com/world   -> world.php 
http://example.com/world/test  -> world.php?id=test 
http://example.com/sth    -> sth.php 
http://example.com/sth/test2  -> sth.php?id=test2 
http://hello.example.com/world/test -> profile.php?subdomain=hello 

而对于其他的文件:

RewriteRule ^dodaj_artykul dodaj_artykul.php [L] 
RewriteRule ^logowanie logowanie.php [L] 
RewriteRule ^rejestracja rejestracja.php [L] 
RewriteRule ^wyloguj wyloguj.php [L] 


RewriteRule ^kategorie/([^-]+)$ kategorie.php?id=$1 [L] 
RewriteRule ^kategorie/$ kategorie.php [L] 
RewriteRule ^kategorie$ kategorie.php [L] 

如果子域存在,一切都被路由到 “?profile.php子域=你好” 如果不存在正常的 “重写规则^ kategorie /([^ - ] +)?$ kategorie.php ID = $ 1 [L]”

回答

1

添加这上面你的其他规则:

RewriteCond %{HTTP_HOST} !^www\. 
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC] 
RewriteRule !^profile\.php$ /profile.php?subdomain=%1 [L,QSA] 
+0

嗯,我有“500内部服务器错误” – xtr3mist

+0

@ xtr3mist对不起,请参阅上面的编辑。 –