2021年5月5日星期三

Intermittent RewriteRule

This is my rewrite rule in .htaccess:

RewriteRule ^quiz/([A-Za-z0-9-]+)/([0-9-]+)/?$ quiz/index.php?inv=$1&d=$2 [NC,L]  

It works perfectly fine for these URLs, which have a mix of cases, with and without hyphens, and all with a date for the final segment:

http://localhost/quiz/C-PFM/2021-04-30/    http://localhost/quiz/cpf-o/2021-04-30/    http://localhost/quiz/ipa/2021-04-30/    http://localhost/quiz/ipacsc/2021-04-30/    http://localhost/quiz/uob-sp/2021-04-30/    http://localhost/quiz/uobsp/2021-04-30/    http://localhost/quiz/Hol-V/2021-04-30/    http://localhost/quiz/HOLVA/2021-04-30/  

That is, $_GET is correctly returning e.g.

inv=HOLVA; d=2021-04-30

As expected.

However, the same rule fails (returns a 404) for each of these examples, which also have a mix of case, and some with hyphen, some without:

http://localhost/quiz/CPFM/2021-04-30/    http://localhost/quiz/cpfo/2021-04-30/    http://localhost/quiz/ipac-sc/2021-04-30/    http://localhost/quiz/GLD10US/2021-04-30/    http://localhost/quiz/HolV/2021-04-30/    http://localhost/quiz/OCBCC/2021-04-30/    http://localhost/quiz/PP/2021-04-30/  

Some of the failing ones could be made to work by adding a hyphen in random places. I did actually try to escape the hyphen in my rule, like this, but it didn't seem to make a difference:

RewriteRule ^quiz/([A-Za-z0-9\-]+)/([0-9\-]+)/?$ quiz/index.php?inv=$1&d=$2    [NC,L]  

I also tried removing NC or the whole [NC,L] and it made no difference.

I also tried both + and * after the first [ ] block, but that didn't make a difference.

The .htaccess file has no other relevant rules that could be conflicting.

Why are the non-working ones not working?

TIA

https://stackoverflow.com/questions/67342565/intermittent-rewriterule May 01, 2021 at 11:14AM

没有评论:

发表评论