I have the following redirect in .htaccess file:
RewriteRule ^tasks/(\w )/?$ /projects.php?task=$1
If I'm trying to access smth like /tasks/nov-1 it will say object not found as \w does not accept "-". Can you please help with adding "-" in the above example redirect rule?
CodePudding user response:
You may use this rule to accept hyphen and also it is recommended to use correct flags in this rule:
RewriteRule ^tasks/([\w-] )/?$ projects.php?task=$1 [L,QSA,NC]
Flags are:
L
is for Last ruleQSA
is for query string appendNC
is for ignore case
Please note that L
flag marks the last rule for current iteration of mod_rewrite
loop. It behaves like continue
in a while
loop not like a break
so it doesn't end the loop immediately. The rewriting process will be started again if the request has been rewritten. So other rules may get applied after the rule with the L
flag.
On Apache 2.4
there is an END
flag which acts like break
and immediately halts the full rewriting process.