Can someone please help me redirect the php pages to html (only in the root directory, without subfolders)? I tried dozens of solutions, but I didn’t succeed. The code below redirects everywhere (including in subfolders…) I don’t want the subdirectories to be affected.
My domain: https://www.example.com/
Thanks in advance!
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+?).php$ /$1.html [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?).html$ /$1.php [L]
</IfModule>
<FilesMatch ".(ico|css|flv|js|gif|jpeg|png|woff|woff2|eot|svg|ttf|webp)$">
Header set Cache-Control "max-age=604800, public, no-cache"
</FilesMatch>
2
Answers
Have it like this:
Note that
[^./]
will match any character that is not a dot and not a/
thus matching only in root directory skipping all sub directories.