views:

1101

answers:

2

I have quite a few RewriteRules in my .htaccess that looks like this

RewriteRule ^something/(\d+)/start    /index.php?ix=$1
RewriteRule ^embed/something/(\d+)/start    /index.php?ix=$1&fEmbed=1

The only difference between these two is the leading "embed/", so I was thinking it would be beneficial to combine these into a single RewriteRule. My attempts are stuck at

RewriteRule ^(embed/)?something/(\d+)/start    /index.php?ix=$2&fEmbed=$1

Which sets "&fEmbed=embed/", which really is not what I want. I want to evaluate the contents of $1, and output something different (namely "1").

Any ideas of how to approach this while combining the first two RewriteRules into a single RewriteRule?

+1  A: 

I think it should be two rules, but they shouldn't do the same thing. The following is untested, but hopefully the intention is clear, if it doesn't work "out-of-the-box":

RewriteRule ^(embed/)?something/(\d+)/start$    /index.php?ix=$2
RewriteRule ^embed/(.*)    $1&fEmbed=1

I'm assuming "/start" is always at the end of the URL. If not then it's a bit more difficult.

EDIT: Reading Vegard's comment I'm thinking that maybe it can be handled by swapping the rules:

RewriteRule ^embed/(.*)    $1&fEmbed=1
RewriteRule ^something/(\d+)/start    /index.php?ix=$1

But still, it depends on real-world applications if this will work or not.

PEZ
The rules don't always end in start, and have more parameters than those shown. However, the idea is good, and I will experiment with it.
Vegard Larsen
A: 

Working with PEZ' idea, this is what I came up with:

RewriteRule ^something/(\d+)/start(&fEmbed=1)?    /index.php?ixQuiz=$1&fStart=1$2
RewriteRule ^embed/(.*)                         $1&fEmbed=1

Not very, pretty, but it works. I can now have multiple rules that start with "something/", and all of them are prefixable by using "embed/".

Vegard Larsen