Apache 重写 url

发布于 2024-09-12 01:22:12 字数 477 浏览 2 评论 0原文

我正在尝试重写 url,但失败了。我可以知道出了什么问题吗?有人请启发我吗?我将代码放在 .htaccess 中。我也启用了 rewrite_module 。

RewriteEngine On
RewriteRule /place/^([a-zA-Z0-9])$ /placelink.php?lid=$1

例如:domain.com/place/xyz -> domain.com/placelink.php?id=xyz

更新

我刚刚发现我的语法现在是正确的。但这并不是 mod_rewrite 不起作用。 phpinfo 显示 mod_rewrite 模块可用。

更新2

RewriteEngine On 
RewriteRule ^/?test\.html$ test.php [L]

I am trying to rewrite url and it fails. May I know what is wrong? Would someone please enlighten me? I placed the code in .htaccess. I have enabled rewrite_module too.

RewriteEngine On
RewriteRule /place/^([a-zA-Z0-9])$ /placelink.php?lid=$1

For example: domain.com/place/xyz -> domain.com/placelink.php?id=xyz

Update:

I have just found out that my syntax is now correct. But it is not mod_rewrite that is not working. phpinfo shows mod_rewrite module is available.

Update 2

RewriteEngine On 
RewriteRule ^/?test\.html$ test.php [L]

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

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

发布评论

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

评论(2

农村范ル 2024-09-19 01:22:12

您很可能想要这个...

RewriteEngine On
RewriteRule ^place/([a-zA-Z0-9-]+)/?$ /placelink.php?lid=$1

这将接受请求...

domain.com/place/the-moon

...并将提供...

domain.com/placelink.php?lid=the-moon

Chances are you want this...

RewriteEngine On
RewriteRule ^place/([a-zA-Z0-9-]+)/?$ /placelink.php?lid=$1

This will take requests for..

domain.com/place/the-moon

...and will serve up...

domain.com/placelink.php?lid=the-moon
心碎的声音 2024-09-19 01:22:12

^ 表示“字符串的开头”。 /path/ 是一个文字。因此,您需要一个包含 /path/ 的字符串,此后字符串开始。这在逻辑上是不可能的。有关正则表达式的更多信息,请参阅 http://regularexpressions.info

^ means 'the start of the string. /path/ is a literal. So you're asking for a string which has /path/ in it, after which the string starts. This is logically impossible. See http://regularexpressions.info for more information about regexes.

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