实现的结果:
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,除了返回502错误的“demo.exemple.com”外,它正在工作。
# 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 :(得分:0)
用这两条规则替换你的2条规则:
# 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]