需要创建一个通用处理程序来检查特定目录中是否存在文件夹。 下面是带有注释的htaccess文件。
Options -Indexes
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#
# redirect www requests
#
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#
# processing the request
#
RewriteCond %{HTTP_HOST} (www\.)?(.*)\.(.*)\.(.*)$
#
# without this line there is an error 500, in the logs there is a loop error
#
RewriteCond %{REQUEST_URI} !subdomains/
#
# if folder exists refers to subdomain
#
RewriteCond %{DOCUMENT_ROOT}/subdomains/%2 -d
RewriteRule ^(.*)$ subdomains/%2/$1 [L,QSA]
#
# if not, and the request does not point to an existing file, then we pass the necessary parameters to the index.php
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?sd=%2&route=$1 [L,QSA]
www.any.example.com - > any.example.com - 确定
existing.example.com - > existing.example.com - 确定
example.com/subdomains/any / - > example.com(index.php?sd =& route = subdomains / any /) - 确定
以下是我无法解决的问题
nonexistent.example.com - > example.com(index.php?sd =不存在) - “sd”中没有数据
决定不传输子域变量并解析它 直接通过脚本本身的HTTP_HOST。
example.com/existingfolder-> example.com(index.php?sd =& route = existingfolder) - 重定向到“example.com/existingfolder/?sd=&route=existingfolder”
谁知道如何解决?