Conditional .htaccess RewriteRule parameter

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

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

      

The only difference between the two is the leading "embed /", so I thought it would be beneficial to combine them into one RewriteRule. My attempts are stuck in

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

      

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

Any ideas on how to approach this by concatenating the first two RewriteRules into one RewriteRule?

0


source to share


2 answers


I think it should be two rules, but they shouldn't do the same. The following is untested, but hopefully the intent 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 am assuming "/ start" is always at the end of the url. If not, then it's a little more complicated.



EDIT: Reading Vegard's comment. I think maybe it could be due to the replacement of the rules:

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

      

But still, it depends on the actual applications if this will work or not.

+1


source


Working with the 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 pretty, but it works. Now I have a few rules that start with "something /" and they are all prefixed with "embed /".

0


source







All Articles