Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 优化htaccess通配符子域代码_.htaccess_Subdomain_Wildcard Subdomain - Fatal编程技术网

.htaccess 优化htaccess通配符子域代码

.htaccess 优化htaccess通配符子域代码,.htaccess,subdomain,wildcard-subdomain,.htaccess,Subdomain,Wildcard Subdomain,我的服务器上有通配符子域,但我想优化.htaccess代码,使其更具可移植性。我不知道怎么做 我想用正则表达式匹配替换下面代码中的特定域名和扩展名domain and.com,以便在为其他域使用通配符代码时可以轻松地进行移植。因此,它应该是domain.com和domain2.net的替代品。以下是我使用的代码: # Wildcard Subdomain RewriteCond %{HTTP_HOST} ^(www.)?([^.]+)\.DOMAIN\.com [NC] RewriteCond

我的服务器上有通配符子域,但我想优化.htaccess代码,使其更具可移植性。我不知道怎么做

我想用正则表达式匹配替换下面代码中的特定域名和扩展名domain and.com,以便在为其他域使用通配符代码时可以轻松地进行移植。因此,它应该是domain.com和domain2.net的替代品。以下是我使用的代码:

# Wildcard Subdomain
RewriteCond %{HTTP_HOST} ^(www.)?([^.]+)\.DOMAIN\.com [NC]
RewriteCond %2 !^www$ [NC]
RewriteRule ^(.*)$ http://DOMAIN.com/$1?a=%2 [R=301,QSA,L]
它与您看到的通常版本略有不同,因为我添加了www.+子域条件的例外。在许多情况下,人们进入www.sub.domain.com时会在服务器上中断。因此,我检查www.并在重定向之前将其删除


谢谢你的帮助

您当前拥有它的方式:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www)\.(.*)\.(.*)\.(.*) [NC]
RewriteCond %2 !^www$ [NC]
RewriteRule ^(.*)$ http://%3.%4/$1?a=%2 [R=301,QSA,L]
如果您只想从域中删除www:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www)\.(.*)\.(.*)\.(.*) [NC]
RewriteRule ^(.*)$ http://%2.%3.%4/$1 [R=301,QSA,L]