【问题标题】:How should I configure '.htaccess' to redirect this?我应该如何配置“.htaccess”来重定向它?
【发布时间】:2021-05-15 20:31:42
【问题描述】:

我在 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...)

我在这里做错了什么?

【问题讨论】:

  • 你能告诉我们什么样的错误,以及浏览器或网络日志文件上的错误消息。
  • "403 - 禁止访问:拒绝访问服务器上的此资​​源!"

标签: apache .htaccess http https


【解决方案1】:

你可以测试一下:

#[ 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] 必须被取消。

【讨论】:

  • “403 - 禁止访问服务器上的此资​​源被拒绝!”,即使在更改之后(谢谢回答)
  • 你重定向到 w.puxir.com,为什么不 www ? w 可能未在您的 dns 服务器中定义。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-04
  • 1970-01-01
  • 1970-01-01
  • 2014-09-25
  • 2012-10-04
相关资源
最近更新 更多