İstenilen sonuç: Şu anda var .htaccess, bir tane elde edebilirsiniz ya da diğer yeniden haritalama ileyeniden .htaccess: GET var olarak GET var ve yol olarak alt alan
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
, ancak ikisini de Aynı zaman.
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]
İkisini birleştirerek zor bir zaman geçiriyorum ... herhangi bir işaretçi, lütfen?
DÜZENLEME
şimdi yaşıyorum istenmeyen davranış bir alt alan adı ve .com/sonra bir yol varsa, sadece alt alan aracılığıyla yani geçilecek olmasıdır:
http://hello.example.com/world-> index.php?subdomain=hello
http://stackoverflow.com/questions/25582265/mod-rewrite-setting-subdomain-and-directory-to-get-variable – shaunw
yeniden yazmak. İki yıl sonra, bunu nasıl çözersiniz? –