I am trying to clear my urls using mod_rewrite in my .htaccess files.
Let's say I have the following files on my server:
/about.php /contact.php
If the user types about or contact , I want about.php or contact.php be displayed to the user, but the URL remains the same (i.e. it all happens on the server side). Similarly, if the user enters about.php or contact.php , I want him to redirect 301 to about or contact , which then pulls out the page on the server side, while maintaining a pretty url.
What I have tried so far:
RewriteEngine on RewriteRule about about.php RewriteRule contact contact.php RewriteRule about.php about [R] RewriteRule contact.php contact [R]
This results in a cyclic redirect cycle.
And vice versa:
RewriteEngine on RewriteRule about.php about [R] RewriteRule contact.php contact [R] RewriteRule about about.php RewriteRule contact contact.php
This is functional, but the redirect does not work (URL remains the same).
How can I do this so that I do not get a redirect loop, but my pages will point to a version without .php ?
Note. I know that [R] - 302 is not 301, but I use 302 for testing.
source share