Where's the error in my .htaccess RewriteRule

2019-08-29 13:22发布

I want this url

http://www.test.racebooking.net/rankings/classifica.html

to point to

http://www.test.racebooking.net/rankings.php

thus, i wrote this rule in my .htaccess file

RewriteRule ^rankings\/[a-zA-Z0-9\-]+\.html$ /rankings.php

I really can't figure out why, when i type the first url, i get a 404 error msg.

  1. RewriteEngine is on.
  2. /rankings.php exists.
  3. Moreover, I have another RewriteRule, much more complex, which i wrote, which is working like charm.
  4. classifica.html doesn't exist. I'm just updating my website with more SEO friendly urls

What's wrong with my rule??

When i test the regexp in any online regexp tester it detects the string "rankings/classifica.html", this means the regexp actually corresponds, but nothing is working....

1条回答
Anthone
2楼-- · 2019-08-29 13:53

I found the error, but i didn't find out why it happens.

Basically, if pattern and substitution start with the same word, the RewriteRule doesn't work.

EXAMPLE

If i write this rule in .htaccess:

RewriteRule ^rankings\/[a-zA-Z0-9\-]+\.html$ /rankings.php

and type this URL

http://www.mywebsite.net/rankings/classifica.html

I get a 404 Error. Even if the Regexp is correct, the apache RewriteEngine is not working. Instead, if i write this rule:

RewriteRule ^ran-kings\/[a-zA-Z0-9\-]+\.html$ /rankings.php

and type this URL

http://www.mywebsite.net/ran-kings/classifica.html

Everything works fine.

查看更多
登录 后发表回答