我应该如何配置'.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...)

我在这里做错了什么?

您可以测试以下内容:

#[ 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]必须被抑制。

最新更新