Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question regarding mod rewrite

Status
Not open for further replies.

Ylisen

Programmer
Jun 19, 2006
2
SE
Hi, I'l try my best to describe my problem. Consider a root directory having 10 numerical directories. In these sub directories there's another bunch of directories containing only numericals. These in turn contains an index.php. What I'd like to do is have a seperate folder with only 1 singel index.php, and when you access for example 1/4/index.php?somevar=value it should become default/index.php?cust=1&hp=4&somevar=value. Other valid ways are to access the same page would be 1/4 and 1/4/. I can't seem to get my regexp to match a ? though. I currently have this:

RewriteRule ^([0-9]+)/([0-9]+)/?[.*]?\??(.*)? default/index.php?cust=$1&hp=$2&$3 [L]

The first part matches perfectly. Then the rules states, that there might be a sequence of any characters, which might be followed by a ?, which in turn might be followed by some more characters which should be stored in $3.

The result of 1/4 becomes default/index.php?cust=1&hp=4 ( correct ).
The result of 1/4/ becomes default/index.php?cust=1&hp=4 ( correct ).
The result of 1/4/asdf=asdf becomes default/index.php?cust=1&hp=4&asdf=asdf ( correct ).
The result of 1/4/?asdf=asdf becomes default/index.php?cust1&hp=4 ( wrong, should end with &asdf=asdf ).
The result of 1/4/index.php?asdf=asdf however becomes default/index.php?cust=1&hp=4&index.php ( wrong, should end with &asdf=asdf ).

I'm not very experienced with regexp so I could really need a hint on this one! Grateful for any replies.
 
Ah, thanks for the help!

However as a consequence another problem has arised which I don't really know if it's possible to solve. All file handling etc is relative to the index.php in for example 1/4/index.php, causing it to malfunction now that the file gets executed in another directory. I've checked the diffrent flags which can be applied but none seems to really solve my problem. Could anyone give me a hint to if it's possible to remedy this problem so that the file gets executed as if it was in 1/4/?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top