【问题标题】:301 redirect works in browser but gives status 200301 重定向在浏览器中有效,但状态为 200
【发布时间】:2017-01-24 13:53:28
【问题描述】:

我添加了一个 ssl 证书,并且只想拥有 https。在浏览器中,http 请求被转发到 https,但 curl -I http://www.domain.com 返回 HTTP/1.1 200 OK。 Afaik googlebot 也将看到状态 200,但必须看到它已永久移动。 .htaccess 错了吗?

WHM 60 (B35)、CentOS 7.3、Wordpress

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Header set Strict-Transport-Security "max-age=31536000; preload; includeSubDomains" env=HTTPS

<IfModule mod_rewrite.c>
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
</IfModule>

【问题讨论】:

    标签: wordpress apache .htaccess redirect


    【解决方案1】:

    我发现下面的代码会返回带有 301 的域、文​​件夹和文件

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-25
      • 2015-07-16
      • 1970-01-01
      • 2012-05-08
      • 1970-01-01
      相关资源
      最近更新 更多