| 12:45 pm on Jan 2, 2013 (gmt 0)|
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;
..from which you could extract your variables as follows:
$mapjt = $matches;
$cmty = $matches;
$tpe = $matches;
| 12:58 pm on Jan 2, 2013 (gmt 0)|
What the bleep bleep? An URL will never contain literal spaces* so what's this set supposed to capture? Or rather, what's it meant to exclude? There's no point in excluding something that would never occur anyway: it's just like saying .+ which is Not A Good Idea. Especially not three separate times, two of them non-final.
It will be much more useful if you give some sample URLs, or explain your naming pattern, so we can see what kinds of material come in those mystery areas:
Once you know what kind of text can and can't occur in those places, you can start on a workable rule. I assume it's something more complicated than [^-]+ or you would have said so.
And if you mean that the whole components like
are optional, then your rule needs a lot more parentheses and question marks.
* Unless, ahem, you have been Very Unwise in your naming.
| 1:23 pm on Jan 2, 2013 (gmt 0)|
Thanks for the replies. dmorison method helps :)
| 8:53 pm on Jan 2, 2013 (gmt 0)|
|the back references ($1, $2 etc.) would change |
Back references look at definitions, not captures. So
should always come through as $1$2$3 even if the content of some captures is null. The tricky part in this one was nesting:
and so on.
| 9:06 pm on Jan 2, 2013 (gmt 0)|
The logic "not spaces, followed by a hyphen" is fatally flawed.
The "not spaces" capture will capture the text, but it will also eat the hyphen and the next text and the next hyphen onwards to the end.
This happens as the text is "not a space" and the hyphen is "not a space".
| 1:37 pm on Jan 21, 2013 (gmt 0)|
As by this: RewriteRule ^([^\ ]+)/for-sale(.*)$ /myfilename.php [L]
it works well. Is there any way to make server keep the order of parameters and redirect to original url if order gets changed like if someone tries with:
then it should be redirected to its original URL:
| 2:46 am on Jan 22, 2013 (gmt 0)|
There are several ways, depending on how many parameters are involved and what happens behind the scenes.
Probably the easiest and most practical way is to let your existing php script take care of it. Before the php starts processing the request, let it look at the parameters. If they're in the wrong order, put them in the right order and issue a redirect. Your php is a lot more flexible than mod_rewrite and can do more complicated calculating and rearranging.
That's assuming it is your own php, not an out-of-the-box CMS that you can't edit. Otherwise it is back to mod_rewrite. Or over to a separate php script which you do write yourself.