我对使用已激活的SSL的htacces重写规则有疑问。
在htacces中,我将所有地址.php
重定向到.html
:
RewriteBase /
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]
如果我添加ssl,则通过以下方式重定向到https:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
将php重写为html无法正常工作。
例如:
http:// domain.com/test.html ---工作
http:// domain.com/test.php->重定向至HTML和工作
https://domain.com/test.php->不推荐-工作
https://domain.com/test.html->错误404-未找到页面
解决了
这是https站点的apache2配置中的问题:
将AllowOverride None更改为AllowOverride All
最佳答案
有这样的规则:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{THE_REQUEST} \.php [NC]
RewriteRule ^(.+?)\.php$ $1.html [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)\.html $1.php [L]
关于php - htaccess使用https将php重定向到html,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23091361/