将http重定向到https - 需要将302重定向更改为301重定向,但无法在.htaccess中找到它

时间:2014-12-22 16:38:22

标签: .htaccess mod-rewrite redirect

我的网站主机配置我的.htaccess将http重定向到https,但Google将其视为302重定向,我相信这会伤害我的搜索引擎优化。

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mydomain1.com
RewriteRule ^(.*)$ https://www.mydomain1.com/$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]


ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 500 default

RewriteEngine On
RewriteRule [^/]+/([\d]+)-.+-([\d]+).html showthread.php?t=$1&page=$2 [NC,L]
RewriteRule [^/]+/([\d]+)-.+.html showthread.php?t=$1 [NC,L]
RewriteRule ^robots.txt$ /robots.php

<IfModule mod_rewrite.c>
    RewriteEngine On

    #   If you are having problems with the rewrite rules, remove the "#" from the
    #   line that begins "RewriteBase" below. You will also have to change the path
    #   of the rewrite to reflect the path to your XenForo installation.
    #RewriteBase /xenforo

    #   This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
        RewriteCond %{HTTPS} off
        RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301] 
</IfModule>

<IfModule litespeed>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^HEAD|GET$
RewriteCond %{HTTP_COOKIE} !skipPageCache
RewriteRule .* - [E=Cache-Control:max-age=60]
</IfModule>

我该如何解决这个问题?此外,这个.htaccess中是否有任何冗余条目?

1 个答案:

答案 0 :(得分:1)

这是您的http->https规则。将其更改为:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
相关问题