首页 > 解决方案 > 我应该如何配置“.htaccess”来重定向它?

问题描述

我在 Hostinger 上有 3 个域,即

'puxir.com' | for hosting
'puxir.org' >> redirect to 'puxir.com'
'puxir.net' >> redirect to 'puxir.com'

以及网站上的 2 个子域:

m.puxir.com > for Mautic
w.puxir.com > for Drupal

目前我正在使用 3 个“.htaccess”文件:

[ public_html/.htaccess ]
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^(m|w)\. [NC, OR]
RewriteCond %{HTTP_HOST} !\.com$ [NC]
RewriteRule ^(.*)$ https://w.puxir.com/%{REQUEST_URI} [L,R=301]

[ public_html/m/.htaccess ]
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !\.com$ [NC]
RewriteRule ^(.*)$ https://m.puxir.com/%{REQUEST_URI} [L,R=301]

[ public_html/w/.htaccess ]
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !\.com$ [NC]
RewriteRule ^(.*)$ https://w.puxir.com/%{REQUEST_URI} [L,R=301]

但现在我被困在试图让一些重定向只在 Apache 上工作。例子:

(R1) http://www.puxir.org >> https://w.puxir.com/
[PASS!]

(R2) http://www.puxir.net >> https://w.puxir.com/
[PASS!]

(R3) http://www.puxir.com >> https://w.puxir.com/
[FAIL!]

(Mind the http/https negotiations above...)

我在这里做错了什么?

标签: apache.htaccesshttphttps

解决方案


你可以测试一下:

#[ public_html/.htaccess ]
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^(m|w)\. [NC,OR]
RewriteCond %{HTTP_HOST} !\.com$ [NC]
RewriteRule ^(.*)$ https://w.puxir.com/%{REQUEST_URI} [L,R=301]

[NC, OR] 中的 [Space] 必须被取消。


推荐阅读