[英]htaccess redirect php to html with https
I have problem with htacces rewrite rule with activated SSL. 我对使用已激活的SSL的htacces重写规则有疑问。
In htacces I have all adress .php
redirected to .html
: 在htacces中,我将所有地址都从.php
重定向到.html
:
RewriteBase /
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]
If I add ssl redirect to https via: 如果我添加ssl,则通过以下方式重定向到https:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Rewrite php to html not working. 将php重写为html无法正常工作。
For example: 例如:
http:// domain.com/test.html --- WORK http:// domain.com/test.html ---工作
http:// domain.com/test.php --> REDIRECTED TO HTML AND WORK http:// domain.com/test.php->重定向至HTML和工作
https:// domain.com/test.php --> NOT REDIRECTED -- WORK https://domain.com/test.php->不推荐-工作
https:// domain.com/test.html --> ERROR 404 - PAGE NOT FOUND https://domain.com/test.html->错误404-未找到页面
SOLVED It was problem in apache2 configuration for https site: 已解决这是https站点的apache2配置中的问题:
change AllowOverride None to AllowOverride All 将AllowOverride None更改为AllowOverride All
Have your rules like this: 有这样的规则:
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]
Try this: 尝试这个:
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php https://%{HTTP_HOST}/$1.html [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html https://%{HTTP_HOST}/$1.php [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.