期望的結果:的.htaccess重寫:子域中GET var和路徑GET變種
http://example.com/ -> index.php
http://www.example.com/ -> index.php
http://hello.example.com/ -> index.php?subdomain=hello
http://whatever.example.com/ -> index.php?subdomain=whatever
http://example.com/world -> index.php?path=world
http://example.com/world/test -> index.php?path=world/test
http://hello.example.com/world/test -> index.php?subdomain=hello&path=world/test
通過的.htaccess我現在所擁有的,我可以實現一個或另一個重映射,但不能同時在同一時間。
RewriteEngine On
# Parse the subdomain as a variable we can access in PHP, and
# run the main index.php script
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{HTTP_HOST} ^([^\.]+)\.([^\.]+)\.([^\.]+)$
RewriteRule ^.*$ index.php?subdomain=%1
# Map all requests to the 'path' get variable in index.php
RewriteBase/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [L]
我很難結合這兩個...任何指針,請?
編輯
意外行爲我現在經歷的是,如果我有一個子域後的.com /路徑,只有子域名會被通過,即:
http://hello.example.com/world-> index.php?subdomain=hello
http://stackoverflow.com/questions/25582265/mod-rewrite-setting-subdomain-and-directory-to-get-variable – shaunw
如果您將VirtualHosts用於處理子域名,而.htaccess處理url改寫。兩年之後,你如何解決這個問題? –