初学者 apache mod_rewrite 帮助

发布于 2024-09-03 08:14:18 字数 190 浏览 2 评论 0原文

我不太熟悉 apache mod_rewrite

我有 url 参数,例如 {domain}/index.php?blog=5

我只是想让它 {domain}/home.php?client=5

是吗这项任务听起来很简单,有人可以帮忙吗?

I am not really familiar with apache mod_rewrite.

I have url parameters such as {domain}/index.php?blog=5

I simply want to make it {domain}/home.php?client=5

Is it a task as simple as it sounds and can anyone help?

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

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

发布评论

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

评论(2

死开点丶别碍眼 2024-09-10 08:14:18

以下可能有效,请尝试一下

RewriteCond %{REQUEST_URI} ^/home.php [NC]
RewriteCond %{QUERY_STRING} client=([0-9]+) [NC]
RewriteRule (.*) http://%{REMOTE_HOST}/index.php?blog=%1 [L]

The following might work, give it a try

RewriteCond %{REQUEST_URI} ^/home.php [NC]
RewriteCond %{QUERY_STRING} client=([0-9]+) [NC]
RewriteRule (.*) http://%{REMOTE_HOST}/index.php?blog=%1 [L]
贱贱哒 2024-09-10 08:14:18

说实话,这看起来很简单——一旦你深入了解 mod_rewrite,它就没有那么复杂了。

听起来您想添加

RewriteEngine on
RewriteRule ^/index.php?blog=(.+)$ /home.php?client=$1

到您的配置中。

一些注意事项:

  • 如果您将其放入 .htaccess 文件中,请从 RewriteRule 行中删除 /
  • 如果您想使其不区分大小写,请将 [NC] 添加到同一行的末尾。
  • 如果您希望用户看到 URL 更改(因此向浏览器发送 302 Found 重定向),请将 [R] 添加到 RewriteRule< 的末尾/代码>行。
  • 如果您希望 302 Found 和 URL 区分大小写,请将这两个指令组合为 RewriteRule 末尾的 [NC,R] 行。

绝对值得阅读 mod_rewrite 文档,但上面的规则应该是这个用例所需的全部。

That seems pretty simple, to be honest — once you get your head into mod_rewrite, it's not that complex.

It sounds like you want to add

RewriteEngine on
RewriteRule ^/index.php?blog=(.+)$ /home.php?client=$1

to your configuration.

Some caveats:

  • If you are putting this in a .htaccess file, then remove the / from the RewriteRule line.
  • If you want to make this case-insensitive, add [NC] to the end of that same line.
  • If you want users to see the URL change (so sending a 302 Found redirection to the browser), then add [R] to the end of the RewriteRule line.
  • If you want both a 302 Found and for the URL to be case-sensitive, combine the two instructions as [NC,R] at the end of the RewriteRule line.

It's definitely worth reading the mod_rewrite docs, but the rule above should be all you need for this use-case.

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