Forum Moderators: phranque
I have a page that can have 3 variables with the url.
for example:
Code:
1) www.site.com/index.php?state=ST
2) www.site.com/index.php?case=BLAH
3) www.site.com/index.php?case=BLAH&state=ST
4) www.site.com/index.php?case=BLAH&town=SOMETOWN
5) www.site.com/index.php?case=BLAH&state=ST&town=SOMETOWN
I have generated the Rewrite Rules like this :
Code:
1) RewriteRule ^([^/]*)\.html$ /index.php?state=$1 [L]
2) RewriteRule ^([^/]*)\.html$ /index.php?case=$1 [L]
3) RewriteRule ^([^-]*)-([^-]*)\.html$ /index.php?case=$1&state=$2 [L]
4) RewriteRule ^([^-]*)-([^-]*)\.html$ /index.php?case=$1&town=$2 [L]
5) RewriteRule ^([^-]*)-([^-]*)-([^-]*)\.html$ /index.php?case=$1&state=$2&town=$3 [L]
I need Rewrite Condition for each of the case above.
Moreover, do i really need the condition ? can't I put all the 5 RewriteRules ? so that which ever is the suited one it will Rewrite Accordingly?
A billion thanks in advance
Zeeshan
You need to 'tag' the directory levels or URL-formats in some way, so that the URL carries some kind of information to tell mod_rewrite which of the query-string formats the URL should be rewritten to. Mod_rewrite looks only at the incoming requested URL defined by the clicked link on your page, and so the URL itself must tell mod_rewrite what to do.
This could be as simple as 'tagging' each virtual directory in the requested URL with a character-sequence, such as
/c-case/s-state.html -or-
/c-case/t-town.html
or you could combine the 'tags' in a top-level virtual directory, and use a URL like
/cs/case/state.html -or-
/ct/case/town.html
or perhaps reverse that, and use
/case/state/cs.html -or-
/case/town/ct.html
Once you decide how you want to do that, we can address some other coding problems with your rules.
Also, since you are rewriting these URLs, you might also want to consider simply leaving off the ".html" at the end, since it serves no real purpose.
Jim