Forum Moderators: phranque

Message Too Old, No Replies

What am I doing wrong? mod rewrite 404 error HELP needed please

         

dwarfham

10:22 pm on Jan 11, 2007 (gmt 0)

10+ Year Member



Hello

My server is hostpc which supports mod_rewrite

I am attempting to hide the .php extension i.e. www.example.com/home.php into www.example.com/home for SEO purposes

However, when I go to www.example.com/home, there is a 404 error that says:

The requested URL /home was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

My .htaccess is as follows:

#<Limit GET POST>
#order deny,allow
#deny from all
#allow from all
#</Limit>
#<Limit PUT DELETE>
#order deny,allow
#deny from all
#</Limit>

php_value register_globals 0

RewriteEngine On
RewriteBase /

#RewriteCond %{REQUEST_FILENAME}\.php!-f
#RewriteRule . /%{REQUEST_FILENAME}\.php
#RewriteCond %{REQUEST_FILENAME}!-d
#RewriteRule (.*) /$1\.php [L]

#RewriteCond %{REQUEST_FILENAME}!-d [AND]
RewriteCond ^%{REQUEST_FILENAME}[\.php]$ -f
RewriteRule (.*) /$1.php [L]

#DefaultType application/x-httpd-php
#ForceType application/x-httpd-php

I have NO idea what is wrong for it works on my other server but not hostpc's

Thanks alot

jdMorgan

10:58 pm on Jan 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That code is pretty badly broken, and I don't see how it could work at all.

Removing the commented-out lines and fixing what's left, we get:


php_value register_globals 0
#
RewriteEngine on
RewriteBase /
#
# Check whether requested URL-path exists as a file when ".php" is appended to it
RewriteCond %{REQUEST_FILENAME}\.php -f
# Rewrite URL-paths which do not contain a period by appending ".php" (if the file exists)
RewriteRule ^([^.]+)$ /$1.php [L]

The new RewriteRule pattern is optional. You cannot use it if you have URL-paths with non-filetype-delimiter periods in them, like "/my.widgets/widget". However, use it if you can, as this will make a large difference in your server performance by eliminating the need to check the filesystem for "file exists" on each and every HTTP request (RewriteConds are not processed if the RewriteRule pattern does not match).

Jim

dwarfham

12:41 am on Jan 12, 2007 (gmt 0)

10+ Year Member



Ohhhh brilliant!

I've been trying to fix this for two days now

Thanks Jim...looks like I still have a lot to learn