Jump to content

Problems being able to remove the .php extension


svgmx5

Recommended Posts

I know this question has probably been answered before. I've looked through most of the posts, yet i can't get it to work. Not sure what I'm doing wrong here but I'm hoping someone can catch whatever it is I'm doing wrong.

 

Below is the code on the .htaccess file that I'm using. The problem is that i keep getting a 404 error.

 

<IfModule mod_rewrite.c>

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

</IfModule>

 

I'm not sure if I'm supposed to use the "<ifModule>" tags, but i tried it both with them and with out then yet i can't get it to work.

 

Again all i want to do is to get the page to look like "www.domain.com/about/" instead of "www.domain.com/about.php"

 

I also have placed the .htaccess file on the root of the directory.

Link to comment
Share on other sites

The IfModule block will simply stop the server from erroring out if mod_rewrite isn't installed. If you don't get 500 Internal Server Errors without them, then you certainly don't need them. With regards to your 404 issue, it's difficult to say, the rules you have seem pretty apt for what your after. As a useful debug tool I always put R=302 in as a flag when I receive errors like this. That way it will perform the re-direct and you will see in the address bar what file you were attempting to serve. Normally this leads to an obvious reason for the 404. If I had to guess I'd go with it being something to do with relative paths, and try putting a forward slash before the $1.php.

Link to comment
Share on other sites

I'm not sure about whether it supports the trailing slash but a

Options +MultiViews

should be all you need. It will also work for other files (eg, images, static HTML pages) so if you specifically don't want that to be possible then we can fix the rewriting instead.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.