哪里是我的.htaccess重写规则正则表达式的错误? [英] Where's the error in my .htaccess RewriteRule Regexp?

查看:124
本文介绍了哪里是我的.htaccess重写规则正则表达式的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这个网址

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

指向

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

因此​​,我在我的.htaccess文件写了这个规则

thus, i wrote this rule in my .htaccess file

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

我实在想不通为什么,当我键入一个URL,我得到一个404错误味精。

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

  1. 在RewriteEngine叙述上。
  2. /rankings.php存在。
  3. 此外,我还有一个重写规则,要复杂得多,这是我 写的,这是工作般的魅力。
  4. classifica.html不存在。我只是更新我的网站 更多的搜索引擎友好的网址
  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

有什么毛病我的规则?

在我测试的正则表达式中的任何在线正则表达式测试仪检测到字符串排名/ classifica.html,这意味着正则表达式实际上对应,但没有什么工作......

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....

推荐答案

我发现了错误,但我也没弄明白为什么会发生。

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.

示例

如果我写在.htaccess中的规则:

If i write this rule in .htaccess:

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

和键入此网址

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

我得到一个404错误。即使正则表达式是正确的,apache的RewriteEngine叙述不工作。相反,如果我写这条规则:

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

和键入此网址

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

一切工作正常。

Everything works fine.

这篇关于哪里是我的.htaccess重写规则正则表达式的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆