Reputation: 21
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
Upvotes: 1
Views: 473
Reputation: 785098
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]
Upvotes: 1
Reputation: 10132
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]
Upvotes: 0