2014-12-24 28 views
1

結果來實現:的.htaccess - 子域名和路徑GET變種

http://example.com/     -> /websites/dispatcher.php 
http://another-example.com/   -> /websites/dispatcher.php 
http://demo.example.com/    -> /websites/dispatcher.php?subdomain=demo 
http://demo.example.com/cat/page.html -> /websites/dispatcher.php?subdomain=demo&path=/cat/page.html 

通過的.htaccess我有,它的工作除了「demo.exemple.com」誰返回502錯誤。

# Parse the subdomain as a variable 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{HTTP_HOST}  !^www 
RewriteCond %{HTTP_HOST}   ^([^\.]+)\.([^\.]+)\.([^\.]+)$ 
RewriteRule ^(.*)$ /$1?subdomain=%1 

# Map all requests to the 'path' get variable in distpacher.php 
RewriteRule ^distpacher\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /distpacher.php?path=$1 [L,QSA] 

我很難過......請幫忙嗎? (。*):

+0

改變最後RewirteRule [L,QSA] **爲* ** RewriteRule ^(。*)$ /distpacher.php?path=$1 [L,R] ** – soewin

回答

0

通過這條規則替換您2本規則自**重寫規則^ $ /distpacher.php?path=$1

# Map all requests to the 'path' get variable in dispatcher.php 
RewriteCond %{HTTP_HOST} !^www [NC] 
RewriteCond %{HTTP_HOST} ^([^.]+)\.[^.]+\.[^.]+$ 
RewriteRule ^/?$ /dispatcher.php?subdomain=%1 [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{HTTP_HOST} !^www [NC] 
RewriteCond %{HTTP_HOST} ^([^.]+)\.[^.]+\.[^.]+$ 
RewriteRule ^(.+)$ /dispatcher.php?subdomain=%1&path=$1 [L,QSA]