正则表达式、modrewrite php apache

发布于 2024-11-08 14:35:23 字数 208 浏览 0 评论 0原文

任何人都可以看到这个问题吗?

url通常是这样的:

page_test.php?page=latest_news&id=10518271191304876236

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ page_test.php?page =$1&id=$2

非常感谢

can any one see the problem with this?

the url is this normally:

page_test.php?page=latest_news&id=10518271191304876236

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ page_test.php?page=$1&id=$2

many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

我的痛♀有谁懂 2024-11-15 14:35:23

您的网址中没有 /,并且您的模式需要一个:

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ page_test.php?page=$1&id=$2
                           ^---here

基本上您正在搜索:

one-or-more alpha-numerics separated by a / followed by one-or-more alphanumerics.

There's no / in your URL, and your pattern is requiring one:

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ page_test.php?page=$1&id=$2
                           ^---here

basically you're searching for:

one-or-more alpha-numerics separated by a / followed by one-or-more alphanumerics.
蝶…霜飞 2024-11-15 14:35:23

由于下划线 _,latest_news 与 [a-zA-Z0-9] 不匹配:您可以使用单词字符类 \w ,其中包含下划线:

RewriteRule ^(\w+)/([a-zA-Z0-9]+)$ page_test.php?page=$1&id=$2

如果 id 始终为数字,您可以使用数字字符类 \d 进一步缩短它:

RewriteRule ^(\w+)/(\d+)$ page_test.php?page=$1&id=$2

latest_news is not matched by [a-zA-Z0-9] because of the underscore _: you could use the word character class \w, which includes the underscore:

RewriteRule ^(\w+)/([a-zA-Z0-9]+)$ page_test.php?page=$1&id=$2

If the id is always numeric, you could shorten it even more using the number character class \d:

RewriteRule ^(\w+)/(\d+)$ page_test.php?page=$1&id=$2
鸠魁 2024-11-15 14:35:23
RewriteRule ^([a-zA-Z0-9_]*)/([0-9]+)$ page_test.php?page=$1&id=$2

您应该从以下位置致电:

www.yourdomain.com/latest_news/10518271191304876236
RewriteRule ^([a-zA-Z0-9_]*)/([0-9]+)$ page_test.php?page=$1&id=$2

and you should be calling from:

www.yourdomain.com/latest_news/10518271191304876236
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文