apache 1.3 和 2.2 上 mod 重写的差异

发布于 2024-07-29 23:12:10 字数 559 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌梦深 2024-08-05 23:12:11

我想到了。 只有最后一条规则才是问题所在。 注意 [^\w] 而不是 [\w'-]。

RewriteRule ^pages/([^\w]+)*$ ./index.php?p=$1

这适用于 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'-].

RewriteRule ^pages/([^\w]+)*$ ./index.php?p=$1

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.

预谋 2024-08-05 23:12:11

尝试将其替换

[\w'-]

[-\w']

:在某些正则表达式解析器中,如果您希望在字符集中使用 -,则它需要是第一个字符,因为它在字符集中具有特殊含义。

Try replacing this:

[\w'-]

with this:

[-\w']

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.

杀お生予夺 2024-08-05 23:12:11

Apache 1.x 使用 POSIX 扩展正则表达式,并且不理解诸如 \w 之类的速记字符类。 所以试试这个:

RewriteRule ^pages/edit(account|page)/([0-9]+)$ ./index.php?p=edit$1&id=$2
RewriteRule ^pages/([A-Za-z0-9_'-]+)$ ./index.php?p=$1

Apache 1.x uses POSIX Extended Regular Expressions and those don’t understand shorthand character classes like \w. So try this:

RewriteRule ^pages/edit(account|page)/([0-9]+)$ ./index.php?p=edit$1&id=$2
RewriteRule ^pages/([A-Za-z0-9_'-]+)$ ./index.php?p=$1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文