优化htaccess的通配符子域code [英] Optimize htaccess Wildcard Subdomain Code

查看:197
本文介绍了优化htaccess的通配符子域code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有通配符子域可以正常使用我的服务器上,而是想优化的.htaccess code,使之更便于携带。我不知道该怎么做。

I have Wildcard Subdomains working perfectly on my server, but would like to optimize the .htaccess code to make it more portable. I'm not sure how to do it.

我想用正则表达式匹配替换特定域名和扩展(域和.com在code以下),这样在使用通配符code其他域就容易端口。 所以应该在更换下降为domain.com和domain2.net 的。这里的code我用:

I would like to replace the specific domain name and extension (DOMAIN and .com in the code below) with a regex match so that when using the wildcard code for other domains it is easy to port. So it should be a drop in replacement for domain.com and domain2.net. Here's the code I use:

# 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.sub.domain.com它打破了服务器上。所以,我检查了www。和调整前将其删除。

It's a little different than the usual version you see, because I've added the exception for the www. + subdomain condition. It many cases people enter www.sub.domain.com which breaks on the server. So I check for the www. and remove it before redirecting.

感谢您的帮助!

推荐答案

您目前拥有的方式​​:

The way you currently have it:

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

如果你只是想要去除从域的WWW:

If you just want to strip the www from the domain:

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

这篇关于优化htaccess的通配符子域code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆