apache 1.3 和 2.2 上 mod 重写的差异
Apache 1.3(.37) 和 2.2(.11) 之间的 mod_rewrite 有什么区别?
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^pages/edit(account|page)/([0-9]+)*$ ./index.php?p=edit$1&id=$2
RewriteRule ^pages/([\w'-]+)*$ ./index.php?p=$1
我写了这个,它“在我的机器上运行”,运行 Apache 2.2.11,但它需要运行的生产服务器是 Apache 1.3.37。 我对 mod 重写非常陌生,今天早上才开始学习正则表达式。 我该去哪里?
更新:我在本地计算机上安装了 Apache 1.3.37。 我收到错误“命令‘RewriteEngine’无效,可能拼写错误或由服务器配置中未包含的模块定义”。
更新 2:我修复了本地计算机遇到的问题。 现在我遇到了与生产服务器相同的问题。
What is the difference in mod_rewrite between Apache 1.3(.37) and 2.2(.11)?
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^pages/edit(account|page)/([0-9]+)*$ ./index.php?p=edit$1&id=$2
RewriteRule ^pages/([\w'-]+)*$ ./index.php?p=$1
I wrote this and it "works on my machine" which is running Apache 2.2.11 but the production server that it needs to run on is Apache 1.3.37. I am really new to mod rewrite and just started learning regex this morning. where do i go from here?
update: I installed Apache 1.3.37 on my local machine. I am getting the error "Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration".
update 2: I fixed the problem i had with my local machine. now i am getting the same issue as on the production server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想到了。 只有最后一条规则才是问题所在。 注意 [^\w] 而不是 [\w'-]。
这适用于 Apache 1.3.37,但不再适用于 Apache 2.2.11。 如果有人知道一种方法让它在两者中都起作用,我真的很想理解这一点,而不仅仅是让它起作用。
I figured it out. Only the last rule was the problem. note the [^\w] instead of [\w'-].
This works with Apache 1.3.37 but no longer functions in Apache 2.2.11. if anyone knows a way to get this to work in both I really want to understand this instead of just making it work.
尝试将其替换
为
:在某些正则表达式解析器中,如果您希望在字符集中使用
-
,则它需要是第一个字符,因为它在字符集中具有特殊含义。Try replacing this:
with this:
In some RegEx parsers, if you want
-
in a character set, it needs to be the first character, as it has a special meaning in character sets.Apache 1.x 使用 POSIX 扩展正则表达式,并且不理解诸如
\w
之类的速记字符类。 所以试试这个:Apache 1.x uses POSIX Extended Regular Expressions and those don’t understand shorthand character classes like
\w
. So try this: