The following code works to hide .php and replace it with .html
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/([^/]*)/([^.]*)\.html/?$ [NC]
RewriteRule ^(.*)$ %1/%2/index.php [L]
I would like to redirect all .php requests to .html. All .php files are inside a sub directory in "https://www.sitename.com/user/". For example
https://www.sitename.com/user/login/index.php
https://www.sitename.com/user/name/index.php
https://www.sitename.com/user/register/index.php
https://www.sitename.com/user/logout/index.php
https://www.sitename.com/user/dashboard/index.php
https://www.sitename.com/user/contact/index.php
It should redirect to
https://www.sitename.com/user/login.html
https://www.sitename.com/user/name.html
https://www.sitename.com/user/register.html
https://www.sitename.com/user/logout.html
https://www.sitename.com/user/dashboard.html
https://www.sitename.com/user/contact.html
Adding separate line of .htaccess code for each folder will be difficult, can someone help with simple code to automatically detect and redirect .php to .html ?
Explanation:
If some try to access "sitename.com/user/login/index.php", it should load "sitename.com/user/login.html".
sitename.com/user/login.html should be the only URL that is visible to users. Even if someone try to access "sitename.com/user/login/index.php", it should redirect/rewrite to "sitename.com/user/login.html".
Enter sitename.com/user/login.html in browser = sitename.com/user/login.html
Enter sitename.com/user/login/index.php in browser = sitename.com/user/login.html
?at the end of your regex should be optional I gues?.htmlextension?