Forum Moderators: phranque

Message Too Old, No Replies

Newbie - Mod Rewrite Help

         

dlogan

9:21 pm on Nov 30, 2006 (gmt 0)

10+ Year Member



I'm trying to get a link in the format of

page.php?cal=myvalue971&getdate=20061123
or
page.php?getdate=20061123&cal=myvalue971

to automatically redirect to
/page/20061123/myvalue971/

But I'm having a really difficult time doing it. Below is what I have so far.

RewriteCond %{query_string} &?getdate=(.*)&? [NC]
RewriteCond %{query_string} &?cal=(.*)&? [NC] [N]
RewriteRule ^page.php [{...] SERVER_NAME}/%1/%1/? [R] [L]

Most of it are bits and pieces I've found different places. I understand the regular expression part, but I'm not sure if I really understand all of the Apache specific options (e.g. query_string, [NC] [N] etc)

The above code I've created when given the URL
[myserver.com...]

(BTW the myvalue971 is does not always end in numbers)
Doesn't do anything and acts like its not even a match. Any ideas? or references to good resources? Thanks!

LifeinAsia

9:50 pm on Nov 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Normally Mod Rewrite is used to go from static URLs to dynamic URLs, not the other way around.
It's probably easier to just process the parameters in page.php and redirect to the new page.

jdMorgan

11:59 pm on Nov 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the variables can be in either order, the simplest solution is to use two rules. But it can be done with one:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{QUERY_STRING}&%{QUERY_STRING} &?getdate=([^&]*)&([^&]*&)*cal=([^&]*)
RewriteRule ^page\.php$ http://{SERVER_NAME}/page/%1/%3/? [R=301,L]

Note that I have avoided the use of the greedy & promiscuous ".*" pattern.

Jim