...

View Full Version : htaccess Mod_Rewrite 404 error



RanDeh
09-02-2011, 03: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.

Thanks,

This what I get with the 404 error:

http://www.articlefinder.info/793/90/Exercise/Algonquin-IL-Personal-Fitness-Trainers-Train-With-the-Best.html

This is what I want:
http://www.articlefinder.info/artid=793&catid=90&title=Algonquin-IL-Personal-Fitness-Trainers---Train-With-the-Best.html


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]
RewriteCond %{REQUEST_METHOD} ^MOVE$
RewriteRule ^/author/(.*)\.php /author/$1.nophp
RewriteRule ^/author/(.*)\.html /author/$1.nohtml
RewriteRule ^/author/(.*)\.htm /author/$1.nohtm
RewriteRule ^/author/(.*)\.js /author/$1.nojs

Cags
09-02-2011, 03: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.

RanDeh
09-02-2011, 04: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!

Regards,

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum