View Full Version : htaccess Mod_Rewrite 404 error

09-02-2011, 02:32 AM
Hi Everyone,

I am trying my hand at a mod_rewrite, although I keep getting a 404 error and from the url if it did work I would not get the results I am looking for. I want to drop the articledetail.php only and keep everything else or is this just impossible. I am hopeful someone here can help me out.


This what I get with the 404 error:


This is what I want:

RewriteEngine on
# Mod Rewrite
Options +FollowSymLinks
#Fix Rewrite
Options -Multiviews
Rewritebase /
RewriteRule ^\.htaccess$ - [F]

RewriteCond %{THE_REQUEST} ^[^/]*/articledetail\.php [NC]
RewriteRule ^articledetail\.php(.+) $1 [R,L]

#Rewrite Rules and conditions below were already in the script and work.
RewriteCond %{REQUEST_METHOD} ^PUT$ [OR]
RewriteRule ^/author/(.*)\.php /author/$1.nophp
RewriteRule ^/author/(.*)\.html /author/$1.nohtml
RewriteRule ^/author/(.*)\.htm /author/$1.nohtm
RewriteRule ^/author/(.*)\.js /author/$1.nojs

09-02-2011, 02:51 PM
Sounds like you are misunderstanding the point of what mod_rewrite does (which is REALLY common). It is intended to take a request for one URI and serve some resource from your actual server.

In your case if Apache receives a request to the server for /author/foobar.php, it would attempt serve up the file /author/foobar.nophp. I'm assuming this isn't actually a file on your server. Assuming you want to achieve the common task of URL's on your site not having file extensions, then you need to flip your view of how it works. At it's most basic you would have something like...

RewriteRule ^/author/(.*)/?$ /author/$1.php

This will then take requests for /author/foobar and serve the file located at /author/foobar.php, therefore you must then change all URLs on your site to point to the extension less path.

NB. If you have this code in your .htaccess file, not in a Vhost file, then the very first forward slash doesn't want to be there.

09-02-2011, 03:52 PM
Hi Cags,

Thanks for taking a look! The reason I want to drop the articledetail.php is just to cleanup the look. I want to keep the following because Google uses them as URL parameters's and by me defining the effect on the content my crawled pages went from 26 to 1,059 in one day. Today it is 1,103 but I understand that's not page ranking at least they are indexed. Maybe it would be best not to mess with it.

Any other input is welcomed!


Keep: artid=793&catid=90&title=