Wordpress and subdomains htaccess [closed]

≡放荡痞女 提交于 2019-12-05 02:33:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!