Home > Software design >  My htaccess file to hide php extensions, isn't working for one single page. It adds a trailing
My htaccess file to hide php extensions, isn't working for one single page. It adds a trailing

Time:02-20

I added the htaccess code below to hide php extensions to one of my websites... it works fine, but one page (video.php), it keeps adding a trailing slash, ending up in a 404 error. I tried different iterations like videos.php, videoo.php, video-new.php, etc. All variations work showing me the page without the php extension, but for some reason "video.php" ends up as "mydomain.com/video/" giving me the 404.

Can anyone figure out what is the cause of this, thank you.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.] )$ $1.php [NC,L]

CodePudding user response:

  • Is the slash not in the link that takes you to this page?

  • Isn't there a cache problem on this page?

  • Have you tried forcing the slash to be removed? It's a bit barbaric and not very clean but it may help you to eliminate a problem and find the cause.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (. )/$ 
RewriteRule ^ %1 [R=301,L]

CodePudding user response:

The problem was that I had a directory with the same name as the file of which I wanted to hide the extension. That was creating a conflict. So to anyone who has the same issue, check to make sure your directories don't share the same exact names as your php files. MrWhite solved my problem. Thank you!

  • Related