I was trying to remove the .php
extension and add a /
as normal websites have. Example http://example.com/category/
.
I use .htaccess
to remove .php
. Here is the code:
RewriteEngine On
RewriteBase /
# hide .php extension snippet
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s([^.]+).php [NC]
RewriteRule ^ %1/ [R,L]
# add a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301]
This code does its task. It removes .php
and adds /
but the PHP page is now not loading.
This is a screenshot (file name test.php
):
How to solve this?
2
Answers
After a few research that is actually working in my case is given below.
It removes the
.php
extension and adds/
at the end of the URL.Output:
Reference: https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/
It is because you’re missing an internal rule to add
.php
silently to such redirect URIs.You can add this rule in the end for that habndling: