Reputation: 8183
I am trying to do a mod-rewrite
in my .htaccess
to get rid of the ".php" file extension.
So basically, here is my site right now: http://www.example.com/about.php
Here is what I want it to be: http://www.example.com/about
Is there a way to do this in my .htaccess using mod-rewrite
? Thanks so much!
Upvotes: 1
Views: 1723
Reputation: 8183
I figured it out! If you ever want this to work for a ".html" extension, you should change the ".php" to ".html"
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
The line with !-d checks that it's not a directory, the line with -f checks that the requested file is a .php file.
To display this though, you need to link to it like this:
<a href="http://www.example.com/about"></a>
Instead of:
<a href="http://www.example.com/about.php"></a>
Because then it will just display the URL as about.php.
Hope this helped anyone looking to do this!
Upvotes: 1