Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- How to apply combinations in one rule?


dmorison - 12:45 pm on Jan 2, 2013 (gmt 0)


Hi sam,

I'm not sure that's possible i'm afraid as whilst the regexp in which each section is optional is straight forward, the back references ($1, $2 etc.) would change.

The alternative is simply to process $_SERVER["REQUEST_URI"] in your script and extract each variable as required. This would use a single rule, e.g.

RewriteRule ^([^\ ]+)/for-sale(.*)$ /myfilename.php [L]

Then at the top of myfilename.php, $_SERVER["REQUEST_URI"] will contain something like;

/for-sale-mapjt-FOO-cmty-BAR-tpe-OOF

..from which you could extract your variables as follows:


preg_match('/mapjt-(.*)[\-]/U',$_SERVER["REQUEST_URI"]."-",$matches);
$mapjt = $matches[1];
preg_match('/cmty-(.*)[\-]/U',$_SERVER["REQUEST_URI"]."-",$matches);
$cmty = $matches[1];
preg_match('/tpe-(.*)[\-]/U',$_SERVER["REQUEST_URI"]."-",$matches);
$tpe = $matches[1];


Thread source:: http://www.webmasterworld.com/apache/4532500.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com