Mod_rewrite
4 posts by 2 authors in: Forums > CMS Builder
Last Post: February 19, 2008 (RSS)
Hi Dave, Would you please post and example of how you did a mod rewrite so a viewer file that shows as:
yourwebsite.com/viewer.php/1/page.php
becomes:
yourwebsite.com/viewer/1/page.php
of course I would choose another name other then "viewer" ... just using that to keep things clear.
Also, can one eliminate the "num" call from the url so it ends up as:
Yourwebsite.com/viewer/page.php
I would really like to replace the "1,2,3 etc" with a directory name so the url ends up like:
yourwebsite.com/viewer/whatido/page.php
I know how to work with your viewerfunction.php file, I am just not clear how dependent the program is on the "num" call for the url.
Thanks!
yourwebsite.com/viewer.php/1/page.php
becomes:
yourwebsite.com/viewer/1/page.php
of course I would choose another name other then "viewer" ... just using that to keep things clear.
Also, can one eliminate the "num" call from the url so it ends up as:
Yourwebsite.com/viewer/page.php
I would really like to replace the "1,2,3 etc" with a directory name so the url ends up like:
yourwebsite.com/viewer/whatido/page.php
I know how to work with your viewerfunction.php file, I am just not clear how dependent the program is on the "num" call for the url.
Thanks!
Re: [Glasairmell] Mod_rewrite
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]
##################### 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.
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.
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
interactivetools.com
Re: [Dave] Mod_rewrite
Thanks!
Here is a good referance for your mod_rewrite.
http://www.ilovejackdaniels.com/mod_rewrite_cheat_sheet.pdf
Mell
Here is a good referance for your mod_rewrite.
http://www.ilovejackdaniels.com/mod_rewrite_cheat_sheet.pdf
Mell