2016-01-21 79 views
0

我想要做的是這樣的:htaccess的重定向所有子域(除WWW)索引與參數

sub.domain.com 

domain.com/index.php?q=sub 

sub.domain.com/somefile.php 

domain.com/sub/index.php?q=sub&file=somefile.php 

sub.domain.com/somefile.php?m=12&r=12 

domain.com/sub/index.php?q=sub&file=somefile&m=12&r=12 

,並保持與子域的地址欄中。

我得到了一些代碼,但它沒有遠程做我需要的東西,所以任何幫助將非常感激。
謝謝!

回答

1
RewriteEngine On 


#Rewrite foo.domain.com/foo/bar to /index.php?q=foo&page=foobar 
#in the condition pattern bellow, we match against any http_host string that doesnt start with www 
RewriteCond %{HTTP_HOST} ^((?!www).+)\.domain\.com$ [NC] 
#if the above condition is met, the rewrite the request 
RewriteRule ^(.*)$ /index.php?q=%1&file=$1 [QSA,NC,L] 
相關問題