Forum Moderators: phranque

Message Too Old, No Replies

problem with mod rewrite?

how to make it work if variable it isn't isset

         

LetItBe

6:07 pm on Apr 4, 2007 (gmt 0)

10+ Year Member



.htaccess:

RewriteEngine on
RewriteRule ^([A-Za-z0-9-_-]+)/([A-Za-z0-9-_-]+)/?$ index.php?primary=$1&secondary=$2 [L]

for example: if I put http://example.com/about/people - it works fine. if I put http://example.com/about/ - this doesn't. how do I make it work if one of the variables isn't set?

thanks

[edited by: jatar_k at 7:09 pm (utc) on April 4, 2007]
[edit reason] please use example.com [/edit]

jdMorgan

7:16 pm on Apr 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need specific rules to handle that kind of situation:

RewriteEngine on
#
RewriteRule ^about/people/?$ index.php?primary=about&secondary=people [L]
#
RewriteRule ^about/?$ index.php?primary=about [L]
#
RewriteRule ^people/?$ index.php?secondary=people [L]
# -or, if "people" is always under "about":
RewriteRule ^people/?$ index.php?primary=about&secondary=people [L]

I supplied two examples for the last rule because I am not aware of how your script works, it's capabilities or limitations, or how your URLs are categorized...

Categorization --putting the URLs to be rewritten into classes or groups that always share a common "method" for being rewritten-- is the biggest part of the job; Once this is done, writing the code is relatively easy. The more consistent and 'formal' the rewriting methodology, the fewer rules you'll need to use.

Also, the possible variations on dynamic names/values and their placement in the static URL are endless, so the above may not be what you really need.

Jim

LetItBe

8:38 am on Apr 5, 2007 (gmt 0)

10+ Year Member



Regarding to your examples I have only added this line:

RewriteRule ^([A-Za-z0-9-_-]+)/?$ index.php?primary=$1 [L]

..and it worked fine!

Thanks a lot, Jim.