Apache htaccess HTTPS重定向所有URL路径

时间:2018-09-19 07:21:55

标签: apache .htaccess https

我要切换到https,我正在尝试为网站上的所有路径设置重定向,以重定向所有非https和非www。路径https://www。但无法正常工作,不确定htaccess中是否有其他冲突。我已经尝试过在这里找到的一些方法,但是无法使所有路径都重定向。不知道是否与网站位于根目录以外的目录有关。

我的htaccess位于public_html / example.com / app / webroot /

当前文件如下:

RewriteEngine On

RewriteRule ^/?stores/view/(.*)$ /stores/$1 [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s/+(.+?)/+[?\s]
RewriteRule /$ /%1 [R=302,NE,L]

# generate rewrite base dynamically
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]

# Pipe request to controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}index.php [L]

RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1     [R=301,L]

编辑:

我想我明白了,我不太确定我在做什么,所以如果有人有办法整理一下,请告诉我:

RewriteEngine On
RewriteBase /

RewriteRule ^/?stores/view/(.*)$ /stores/$1 [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s/+(.+?)/+[?\s]
RewriteRule /$ /%1 [R=302,NE,L]

# generate rewrite base dynamically
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]

RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,NE,R=302]

# Pipe request to controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}index.php [L]

0 个答案:

没有答案