views:

40

answers:

1
RewriteRule ^foo-bar-([0-9]+)-([a-z]+)-([a-z-+]+)/$ index.php?a[]=&b=$1&c=$2&d=$3&e=$4&f=$5 [L,NC]

how could i put the last parameter from rule to not be required without to add two lines and in first one to remove it, then in second to remain..?

so, rule to be in one line but to have two option to acees url like:

/foo-bar-2-steps/

/foo-bar-2-steps-eq/
+2  A: 

One of the following:

  • Use two rewrite rules, one for each case
  • Put a question mark after the optional part, like this:

foo-bar-([a-z]+)(-([a-z]+))?

Here, the second parameter is optional. Note that this changes your numerical indexes, since you use extra parenthesis.

Sjoerd
Thank you Sjoerd, it`s working.Now i have one more question:How could i make a variable in htaccess then use it in all RewriteRule like:RewriteRule ^(sone|another|etc)....RewriteRule ^(sone|another|etc)....to be:setenv var (sone|another|etc)RewriteRule ^(env:var)....
oriceon
Each () defines a variable. You can access the first () by $1, the secound by $2, ...
JochenJung
I know that. There was another think. I want to set a variable in .htaccess then to use it in all my RewriteRule to not repeat a code each time.. If i want to change one option from that variable.. to do it quickly.
oriceon