htaccess mod_rewrite url 的一部分到 GET 变量

发布于 2025-01-04 13:20:22 字数 558 浏览 2 评论 0原文

我有一些像这样的网址:

  • http://plutov.by/post/cubique_zf_jquery
  • http://plutov.by/post/mysql_useful_queries

我如何在 Apache 的帮助下mod_rewrite 打开下一页?

  • http://plutov.by/post/main?title=cubique_zf_jquery
  • http://plutov.by/post/main?title=mysql_useful_queries

另外,将是这个新的重写规则与“一个入口点重写”一起使用吗?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

谢谢。

I have some URLs like these:

  • http://plutov.by/post/cubique_zf_jquery
  • http://plutov.by/post/mysql_useful_queries

How can I with help of Apache mod_rewrite open the next pages?

  • http://plutov.by/post/main?title=cubique_zf_jquery
  • http://plutov.by/post/main?title=mysql_useful_queries

Also, will be this new rewrite rule work with "one entry point rewriting"?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Thanks.

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

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

发布评论

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

评论(2

胡大本事 2025-01-11 13:20:22

要使新的重写规则与“一个入口点重写”一起使用,请让您的 rewriteRules 如下所示:

QSA 标志是强制,就像您一样添加新的查询字符串。

RewriteEngine On

RewriteRule ^(post)/([\w\d\-]+)/?$ $1/main?title=$2 [QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . index.php [L]

To make the new rewrite rule work with "one entry point rewriting", have your rewriteRules like this:

The QSA flag is mandatory as you are adding a new query string.

RewriteEngine On

RewriteRule ^(post)/([\w\d\-]+)/?$ $1/main?title=$2 [QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . index.php [L]
╰つ倒转 2025-01-11 13:20:22

您可以在 .htaccess 中使用类似的内容:

RewriteRule ^post/(.*)$ post/main?title=$1 [L]

您应该在一个入口点重写规则之前保留此规则。如果规则将触发,则重写规则查找将完成(因为指定了 [L] 选项)

如果您想在 VirtualHost 上下文中使用这些规则,可能需要对路径进行一些修改

You can use something like this in your .htaccess:

RewriteRule ^post/(.*)$ post/main?title=$1 [L]

You should keep this rule BEFORE one entry point rewriting rules. If rule will trigger then rewrite rule lookup will be finished (since [L] option specified)

Some modification of paths may be required if you want to use these rules in VirtualHost context

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