Forum Moderators: phranque

Message Too Old, No Replies

dynamic to static urls using mod_rewrite

i know this has been explored just posting something that worked...

         

tqatsju

4:43 am on Feb 16, 2005 (gmt 0)

10+ Year Member



ok i figured out from previous posts how to make my dynamic urls static here goes

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
//allows you to have apache recognize html files as php
AddHandler application/x-httpd-php .html
AddHandler application/x-httpd-php .htm

RewriteRule (^.*)/(.*)/(.*)\.html$ tickets.php?venue=$1&event=$2&date=$3 [L]

ok so now i can write urls like this

domainname.com/venue-name/event-name/date.html
and my script gets....
tickets.php?venue=venue-name&event=event-name&date=date

but what i'm asking (especially JD hint hint...) is there a safer way of doing this....and also just to post it in case you are looking for a way

thanks, Tom

hakre

11:49 am on Feb 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



your way seems a little chaotic to me. maybe you should let yourself being inspired by some other people who did similar things. that might help you making it even better.

andreasfriedrich was so nice to post a complete text about how "Getting rid of those query strings". it's msg #:4 in the Bag-O-Tricks for PHP II - Thread [webmasterworld.com] here on webmasterworld.

you maybe wonder why i'm suggesting further reading? okay, this made it suspicious to me: mapping .html files to php in apache is one thing, removing querystrings another. with

RewriteRule
there is no need of
AddHandler
, so i suggested you the thread above, because that one is using ModRewrite.

jdMorgan

4:08 pm on Feb 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Without knowing all the details, I'd rewrite it as:

# allows you to have apache recognize html files as php
AddHandler application/x-httpd-php .html .htm
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^([^/]+)/([^/]+)/([^.]+)\.html$ /tickets.php?venue=$1&event=$2&date=$3 [L]

This avoids the use of the ambiguous and terribly-inefficient ".*" pattern, and combines your two AddHandlers into one.

Jim