svgmx5 Posted August 5, 2011 Share Posted August 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243898-problems-being-able-to-remove-the-php-extension/ Share on other sites More sharing options...
cags Posted August 5, 2011 Share Posted August 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243898-problems-being-able-to-remove-the-php-extension/#findComment-1252519 Share on other sites More sharing options...
svgmx5 Posted August 12, 2011 Author Share Posted August 12, 2011 None of that worked ...i really need to get this figured out but i just don't know why its giving me an error. Any more advice?? Quote Link to comment https://forums.phpfreaks.com/topic/243898-problems-being-able-to-remove-the-php-extension/#findComment-1256613 Share on other sites More sharing options...
requinix Posted August 12, 2011 Share Posted August 12, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243898-problems-being-able-to-remove-the-php-extension/#findComment-1256618 Share on other sites More sharing options...
svgmx5 Posted August 12, 2011 Author Share Posted August 12, 2011 So i rewrote the script to the following: <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine on RewriteRule ^([^\.]+)$ $1.php [NC,L] </IfModule> And if i type www.domain.com/about i still get a 404 error Quote Link to comment https://forums.phpfreaks.com/topic/243898-problems-being-able-to-remove-the-php-extension/#findComment-1256636 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.