将http://domain.com/重定向到https://domain.com问题

时间:2017-02-08 07:24:41

标签: php .htaccess redirect

我知道这是一个重复问的问题,但事情是我甚至找不到答案。最近,我们决定使用https,因此我们希望重定向所有内容。在检查其他域名后,我看到http://domain.com/accommodation/重定向到https://domain.com/index.php。你能告诉我我的代码有什么问题吗?

对于根目录:

<IfModule mod_rewrite.c>
    RewriteEngine On
     RewriteBase /sample/public
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>


#IP Canonicalization Test with sample IP 
RewriteCond %{HTTP_HOST} ^222\.222\.22\.222
RewriteRule (.*) https://domain.com/$1 [R=301,L]

#URL Canonicalization Test
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule (.*) https://domain.com/$1 [R=301,L]

对于公共目录:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On


    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]


    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

#IP Canonicalization Test with sample IP 
RewriteCond %{HTTP_HOST} ^222\.222\.22\.222
RewriteRule (.*) https://domain.com/$1 [R=301,L]

#URL Canonicalization Test
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule (.*) https://domain.com/$1 [R=301,L]

#Added this for assurance for redirection
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]

感谢您帮助我。

和平!

0 个答案:

没有答案