如何使用mode_rewrite函数

发布于 2024-10-05 21:02:03 字数 707 浏览 0 评论 0原文

我想知道如何正确使用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 技术交流群。

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

发布评论

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

评论(1

歌枕肩 2024-10-12 21:02:03

您在替换中使用绝对路径 / 。因此,当在 /page/ 中的 .htaccess 文件中使用此规则时,/page/start.html 的请求实际上会被重写为 /?m=start 而不是 /page/?m=start

尝试使用相对路径:

RewriteRule ^([^/]*)\.html$ ./?m=$1 [L]

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:

RewriteRule ^([^/]*)\.html$ ./?m=$1 [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文