本文介绍了有没有办法将这些重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个重定向(一个用于HTTP,一个用于HTTPS):
I have two redirects (one for http and one for https):
# Option 1a: rewrite www.example.com → example.com
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>
# Option 1b: rewrite https://www.example.com → https://example.com
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
</IfModule>
是否有可能将它们合并,并删除的子站点的HTTP和HTTPS有一个规则集(无需指定确切域,像现在的规则)?
Is it possible to combine them, and remove the subdomain for both http and https with one ruleset (without having to specify the exact domain, like the current rules)?
推荐答案
下面是你可以两个规则组合成一个没有硬编码主机名:
Here is how you can combine both rules into one without hardcoding hostname:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST}#%{HTTPS}s ^www\.([^#]+)#(?:off|on(s)) [NC]
RewriteRule ^ http%2://%1%{REQUEST_URI} [R=301,L]
</IfModule>
这篇关于有没有办法将这些重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!