Mod_rewrite

4 posts by 2 authors in: Forums > CMS Builder
Last Post: February 19, 2008   (RSS)

Re: [Glasairmell] Mod_rewrite

By Glasairmell - February 17, 2008

This is what I ended up using for my specific application.

##################### REWRITE RULES #####################

Options +FollowSymlinks

RewriteEngine On
RewriteBase /

RewriteRule ^/?([^/]*)/([0-9]*)/?([^/]*)$ $1.php?$2 [L]

Re: [Glasairmell] Mod_rewrite

By Dave - February 18, 2008

Thanks for posting that.

I haven't actually done a lot with mod_rewrite (other than copying and pasting other code) so I'll use that as a base when exploring it more.

You can drop the number and lookup records by something else. It just requires a bit of custom PHP and MySQL. Basically you just create a field in the editor called 'filename' (or whatever you like), make it unique, and query that in the where clause option like this:

$options['where'] = 'filename = "/whatido/page.php"';

You just need a little PHP code to pull that part out of the url, escape it, and then put it in the where clause. Try this in your page viewer code.

$escapedFilename = escapeMysqlString( @$_SERVER['PATH_INFO'] );
$options['where'] = "filename = '$escapedFilename'";


Test it out by adding: print $options['where']; after to make sure it's printing the right thing.

Hope that helps! Let me know how it goes.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Mod_rewrite

By Glasairmell - February 19, 2008

Thanks!

Here is a good referance for your mod_rewrite.

http://www.ilovejackdaniels.com/mod_rewrite_cheat_sheet.pdf

Mell