I have tried to remove the .php extension and nothing seems to work.
First, here is what I am trying to accomplish:
Current URL: www.example.com/something.php
Desired URL: www.example.com/something
Second, here is what I have in my .htaccess file:
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]
RewriteRule (.*)/$ $1.php [L]
</IfModule>
Lastly, here is the issue:
Instead of getting www.example.com/something I get www.example.com/something/ and my pages can no longer find their css, js or image files. Also when I click an internal link it changes my url to www.example.com/something/link and it will keep adding to the url as I click through the page until I get something like this: www.example.com/something/link/link2/something/link1/something
The goal here is to just remove the .php file extension to the public as mentioned above.
Thanks, Ben
Source: Tips4all
Use the following instead:
ReplyDeleteRewriteEngine 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.
I know this is an old post but hopefully this will help someone else.
ReplyDeleteBelow is what I have that works on Godaddy.
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]
The only thing different is that I added the RewriteBase /