php - apache配置.htaccess使http转向https
大家讲道理
大家讲道理 2017-04-11 09:48:56
0
2
837

现在网站http和https都可以访问,但希望访问的时候http直接跳转到https上去

这是我配置的.htaccess

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
#RewriteRule (.*) https://%{SERVER_NAME}/$1 [R]
</IfModule>

加入那两行后就打不开了,求解中~

网站:https://www.ineedtm.com

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

Antworte allen(2)
迷茫

这几天刚好在做同样的事情。

看你的htaccess,应该是也使用了php框架或者整站软件了,我也用了。

先上没有框架的,适合纯html和没有php路由的简单网站

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

</IfModule>

有框架的也好办:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

把https改写放在前面,先把url从http改成https,之后再进行php框架的改写。

阿神

stackoverflow查了下,更改后下面就可以了。楼上的大家可以参阅下

<IfModule mod_rewrite.c>
      Options +FollowSymlinks
      RewriteEngine On

      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
     RewriteCond %{HTTPS} off
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!