apache - 我应该如何配置“.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] 必须被取消。
推荐阅读
- java - 当 List 为空时 Spring Boot 返回 204 No-Content
- powerbi - Power BI - 词云 - 前 N 个词
- python - 带有逻辑索引的散点图
- php - Session_start 不断重新加载页面
- c++ - 模板定义的宏
- string - 如果字符串文字在整个程序期间都处于活动状态,它们如何具有不同的生命周期?
- jsf - 无法使用 selectManyCheckbox 在对象数组列表中添加对象
- css - 仅使用 CSS 设置特定元素的相等高度?
- chatbot - Microsoft Chatbot 框架返回 Facebook Messenger 的 HTTP 状态代码 InternalServerError
- javascript - google sheet api v4 clear 命令 POST 格式