Where's the error in my .htaccess RewriteRule Regexp?

夙愿已清 提交于 2019-12-12 03:08:44

问题


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:


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.



来源:https://stackoverflow.com/questions/20274123/wheres-the-error-in-my-htaccess-rewriterule-regexp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!