Skip to content Skip to sidebar Skip to footer

.htaccess Redirect All Extension To Php

I recently updated my .htaccess file to hide the .php extension of the urls. It works nice, when I try to reach domain.com/index, it displays the php file. When I type domain.com/i

Solution 1:

You could try something like this:

# php extension to no extension url
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteRule ^(.+)\.[a-zA-Z0-9]+$ $1 [R=301,L]

Then it will not only redirect .php extension, but anyone. To use it, be sure that you dont have URL with a dot and an alphanumeric string at the end.

Post a Comment for ".htaccess Redirect All Extension To Php"