.htaccess rewrite: Subdomain als GET var und Pfad als GET var
Erwünschtes Ergebnis:
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
Mit dem .htaccess, den ich gerade habe, kann ich das eine oder andere Re-Mapping durchführen, aber nicht beide gleichzeitig.
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]
Es fällt mir schwer, die beiden zu kombinieren ... bitte irgendwelche Hinweise?
BEARBEITEN
Das unerwünschte Verhalten, das ich jetzt erlebe, ist, dass wenn ich eine Unterdomäne und einen Pfad nach .com / habe, nur die Unterdomäne durchgelassen wird, dh:
http://hello.example.com/world-> index.php?subdomain=hello