【问题标题】:htaccess: URL with any URI not redirecting to https://wwwhtaccess:带有任何 URI 的 URL 不重定向到 https://www
【发布时间】:2018-09-21 02:09:58
【问题描述】:

目前,这是我的 .htaccess 文件:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Redirect to HTTPS
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

    # Send would-be 404 requests to Craft
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    RewriteRule (.+) index.php?p=$1 [QSA,L]

    # Custom Redirects
    Redirect /investors/reporting/estma /investors/investor-reporting/financial-information#estma
    RewriteCond %{HTTP_HOST} ^portal\.arcresources\.com [NC]
    RewriteRule ^(.*) https://www\.arcresources\.com/portals [L,R=301]
</IfModule>

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>

如果您只需键入域,重定向就可以正常工作,因此 arcresources.com 会正确重定向到 https://www.arcresources.com。如果您包含 www 和任何 URI,它也可以工作,因此 www.arcresources.com/investors 也可以正确重定向。

问题在于仅输入域 + URI,因此 arcresources.com/investors 仅重定向到 https://arcresources.com/investors(没有 www.),导致连接被拒绝。

我确定我遗漏了一些简单的东西,但到目前为止,我的所有尝试要么添加了双“www”,要么导致了过多的重定向。

提前致谢:)

【问题讨论】:

    标签: .htaccess https


    【解决方案1】:

    试试这样:

    RewriteEngine On
    RewriteBase /
    
    # Redirect HTTP with www to HTTPS with www
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    # Redirect HTTP without www to HTTPS with www
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    # Redirect HTTPS without www to HTTPS with www
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    
    # Send would-be 404 requests to Craft
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    #RewriteCond %{REQUEST_URI} !index.php  [NC]
    RewriteRule (.+) index.php?p=$1 [QSA,L]
    

    【讨论】:

    • 在新的浏览器中以隐身模式测试它。
    • 奇怪的是,它重定向到 https://www。万维网。 arcresources.com。客户端控制着 DNS 和域,所以我不确定那里到底发生了什么。有什么方法可以让我原来的重写工作?它似乎是唯一一个不会把事情搞砸的人
    • 将其添加到我原来的“# Redirect to HTTPS”代码中?不,我没有。由于它适用于除“arcresource.com/some-uri”之外的所有内容,因此我没有弄乱它。
    • 这给了我错误:“www.arcresources.com 重定向你太多次”
    • 我添加了一个更严格、更详细的版本。
    猜你喜欢
    • 2022-01-11
    • 2018-06-02
    • 2021-11-10
    • 2012-12-23
    • 2016-09-01
    • 2012-02-06
    • 2018-07-03
    相关资源
    最近更新 更多