问题
I currently have Wordpress installed in the base path of my server. Wordpress uses htaccess for user-friendly URL's. In addition I have the need of wildcarded subdomains, as I have users wanting to access a specific system.
When the user visits www.domain.com, or just domain.com, they should be served Wordpress. If they are requesting giraffesinafrica.domain.com, the dir should be set to /system/ (a folder in base path)
In the folder /system/ i have another .htaccess controlling the URLS redirected into that..
I hope someone can lead me on the way :)
Thanks in advance!
RewriteEngine On
# 3. internal redirect to the shop
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$
RewriteRule ^(.*)$ subdomain/ [L,NC,QSA]
# BEGIN WordPress
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./index.php [L]
# END WordPress
回答1:
You talk about /system, while your code uses /subdomain, so I will use the latter.
RewriteEngine On
# rewrite subdomains to separate folder
RewriteRule ^subdomain/ - [L]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$
RewriteRule ^(.*)$ subdomain/$1 [L]
# or if you want to rewrite sub.domain.com/test to /subdomain/sub/test
#RewriteRule ^(.*)$ subdomain/%1/$1 [L]
# force www
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R]
# BEGIN WordPress
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./index.php [L]
# END WordPress
来源:https://stackoverflow.com/questions/8368473/wordpress-and-subdomains-htaccess