views:

92

answers:

1

Hello, First off I wanna apologize for my ignorance but mod_rewrite and regex seems just a bit complicated for me and I need this done fairly quickly. Basically what I'm trying to accomplish is the followings:

  1. Get rid of the .php extensions and get rid of the index.php - Basically when a user enters http://www.example.com/index.html to be redirected to http://www.example.com/ if he or she enters anything else than .html to get a 404 page not found.

  2. I'm using IDs to grab the title from the DB. I would like to rewrite /?id=1 (each number corresponds to a title in the DB) to /title_name.html.

  3. If a user types in /unknown_title (the title is not found in the DB) or …?bleh=hey (or any other similar nonsense) to redirect him or her to 404.html.

I managed to make one of the three work but I don't know how to redirect the user any of the wanted cases. If anyone could help with this I would really appreciate it! Thanks a lot in advance.

+1  A: 

How about make a url handler in PHP? Drop something like this in your http.conf or root .htaccess

RewriteEngine on    
RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php

Then have index.php deal with the all the logic of what files to require for given URLs. You could knock this out pretty darn quick.

All the things you want to do are integral in a good web framework. My advice on that front is Django. It is Python, and that may add a slight learning curve, but your overall sanity will benefit. :)

SleighBoy