php - How to treat two different parameter with same file name in htaccess?
Get the solution ↓↓↓Here is what I mean using the example I have two types of links like-
http://example.com/type.php?category=movies
http://example.com/type.php?tags=movies
And I have used some code like this in htaccess
RewriteRule ^type/([0-9a-zA-Z_-]+) type.php?category=$1 [NC,L]
RewriteRule ^type/([0-9a-zA-Z_-]+) type.php?tags=$1 [NC,L]
But still no luck, the first one code that is on the first line of other like in this case the ?category only works and the ?tags don't work what could be the possible correct answer to tackle both?
Thanks in advance!
Answer
Solution:
Try to remove the L from [NC,L] because it means that if .htaccess can apply this rule, you tell it to stop the rewriting here and so it won't execute the second line.
Here's more about the flags : https://httpd.apache.org/docs/2.4/en/rewrite/flags.html\
" The [L] flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed. "
=-=
Also, as Chris Haas commented, if you're not enough specific about your rules and that the original URL from first rule is found in all other rules, then it will always only process first rule.
A good example to this is :
RewriteRule ^([a-z0-9_]+)/([a-z0-9_]+)/([a-z0-9_]+)$ index.php?param1=$1\
RewriteRule ^([a-z0-9_]+)/([a-z0-9_]+)/([a-z0-9_]+)$ index.php?param1=$1¶m2=$2\
RewriteRule ^([a-z0-9_]+)/([a-z0-9_]+)/([a-z0-9_]+)$ index.php?param1=$1¶m2=$2¶m3=$3\
As the first rule can be found in other rules (here both 2nd and 3rd, then these 2nd and 3rd will be considered as "same" as the first one and therefore not executed.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string deprecated
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.