我是否可以通过某种巧妙的正则表达式来修改此工作.htaccess
,以处理多个子域的重定向。
理想情况下,我希望能够使用我的joshmoto.wtf
域而无需在前面放置www
。
是否可以使当前的.htaccess
功能如下所示?
如果您访问...
请参见下面的当前.htaccess
,它始终将http://joshmoto.wtf重定向到https://www.joshmoto.wtf
<IfModule mod_rewrite.c>
# Force SSL access
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.joshmoto\.wtf [NC]
RewriteRule ^/?(.*) https://www.joshmoto.wtf/$1 [L,R,NE]
</IfModule>
任何专家正则表达式的帮助将不胜感激。
非常感谢
答案 0 :(得分:1)
像这样尝试:
RewriteEngine On
RewriteBase /
# Redirect HTTP with www to HTTPS without www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.joshmoto\.wtf$ [NC]
RewriteRule .* https://joshmoto.wtf%{REQUEST_URI} [R=301,L]
# Redirect HTTP without www to HTTPS without www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect HTTPS with www to HTTPS without www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.joshmoto\.wtf$ [NC]
RewriteRule .* https://joshmoto.wtf%{REQUEST_URI} [R=301,L]