【问题标题】:htaccess redirect avoid specific domainshtaccess 重定向避免特定域
【发布时间】:2016-03-30 02:24:02
【问题描述】:
RewriteCond %{HTTP_HOST} !^(www\.)?(domaintoavoid1|domaintoavoid)\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^(www\.)?(domaintoavoid1|domaintoavoid2)\.com$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https%1://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

我目前有这个 www/https 重定向,但我有某些域没有设置 SSL 证书,我希望能够完全绕过重定向。虽然它目前不起作用,但 domaintoavoid.com 和 www.domaintoavoid.com 仍会被重定向到 https。

【问题讨论】:

  • https%1 -- 你为什么有%1?看起来它会从(www\.) 捕获。
  • 我认为 %1 没有必要。但是它如何捕获 (www\.) 作为条件是否定的?
  • 似乎你有很多多余的东西在那里发生。当您重定向到 https 时,您是否希望在您的 URL 上有 www?并且反向引用没有帮助。

标签: .htaccess redirect ssl


【解决方案1】:

在单独的规则中这样写

# skip these domains from https/www rule
RewriteCond %{HTTP_HOST} ^(?:www\.)?(?:domaintoavoid1|domaintoavoid)\.com$ [NC]
RewriteRule ^ - [L]

RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301,NE]

确保在测试之前清理浏览器缓存。

【讨论】:

    猜你喜欢
    • 2021-11-17
    • 1970-01-01
    • 2017-08-16
    • 1970-01-01
    • 2011-11-24
    • 2014-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多