Apache 重写 url
我正在尝试重写 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您很可能想要这个...
这将接受请求...
...并将提供...
Chances are you want this...
This will take requests for..
...and will serve up...
^
表示“字符串的开头”。/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.