I have problem with htacces rewrite rule with activated SSL.
In htacces I have all adress .php
redirected to .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:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Rewrite php to html not working.
For example:
http:// domain.com/test.html --- WORK
http:// domain.com/test.php --> REDIRECTED TO HTML AND WORK
https:// domain.com/test.php --> NOT REDIRECTED -- WORK
https:// domain.com/test.html --> ERROR 404 - PAGE NOT FOUND
SOLVED It was problem in apache2 configuration for https site:
change AllowOverride None to 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]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.