如何使用mode_rewrite函数
我想知道如何正确使用php的函数mode_rewrite。 我目前正在使用 xampp 进行开发。我已在 httpd.conf 文件中激活 LoadModule rewrite_module module/mod_rewrite.so
。 我还编辑了以下几行:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
在我的 .htaccess 文件中,我有以下代码:
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /?m=$1 [L]
因此应该将 ?m=start
更改为 ?start.html
。 当我现在打开 localhost/page/start.html 时,它只显示“它有效”。但为什么它不向我显示来自 localhost/page/?m=start 的内容?
进一步的问题是,如何更改重写规则,以便我可以通过 localhost/page/start/update.html 访问 localhost/page/?m=start&set=update ?
谢谢您的答复!
I'd like to know, how I can use php's function mode_rewrite correctly.
I'm currently developing with xampp. I've activated LoadModule rewrite_module modules/mod_rewrite.so
in the httpd.conf file.
Also I edited following lines:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
In my .htaccess file, I've following code:
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /?m=$1 [L]
So it should change ?m=start
to ?start.html
.
When I now open localhost/page/start.html
, it only shows me "It works". But why doesn't it show me the content from localhost/page/?m=start
?
A further question would be, how do I change the rewrite rule, that I could access localhost/page/?m=start&set=update
through localhost/page/start/update.html
?
Thank you for an answer!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在替换中使用绝对路径
/
。因此,当在/page/
中的 .htaccess 文件中使用此规则时,/page/start.html
的请求实际上会被重写为/?m=start
而不是/page/?m=start
。尝试使用相对路径:
You are using the absolute path
/
in your substitution. So when using this rule in the .htaccess file in/page/
a request of/page/start.html
will actually be rewritten to/?m=start
and not/page/?m=start
.Try a relative path instead: