Somenath Sinha Somenath Sinha - 4 months ago 14
PHP Question

How to automatically eliminate the file name from the url?

I'm already using RewriteEngine and RewriteConditions to eliminate the .php part from the file name.

However, I visited this site recently,

http://poorlydrawnlines.com/comic/tragedy/
. In it, just to mess around, I tried finding the actual file name, which turned out to be index.php. However, when I tried to go to
http://poorlydrawnlines.com/comic/tragedy/index.php
, the site automatically shortens the url to
http://poorlydrawnlines.com/comic/tragedy/
. How is this behavior achieved?

Also, am I correct in assuming that the page's original address ends in index.php? Or is the site simply redirecting me? How do I recreate this in my own websites?

Answer

Since you have not provided your original .htaccess code this is the best i can do.

RewriteCond %{THE_REQUEST} ^.*/index\.php 
RewriteRule ^(.*)index.php$ /$1 [R=301,L]