URL重写apache2

发布于 2024-12-23 15:14:54 字数 311 浏览 4 评论 0原文

我如何才能将

anyhost.com/argument1/parameter2/some-text/

重写为

anyhost.com/index.php?path=argument1/parameter2/some-text/ code>

anyhost.com/index.php?page=argument1&subpage=parameter2&subsubpage=some-text

或类似的东西?

How would I be able to rewrite

anyhost.com/argument1/parameter2/some-text/

as

anyhost.com/index.php?path=argument1/parameter2/some-text/

or

anyhost.com/index.php?page=argument1&subpage=parameter2&subsubpage=some-text

or anything like that?

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

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

发布评论

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

评论(2

风渺 2024-12-30 15:14:54

这应该可以做到:

RewriteEngine On

# First example
RewriteRule ^(.*)$ index.php?path=$1 [L,QSA]

# Second example
RewriteRule ^(.*)/(.*)/(.*)$ index.php?page=$1&subpage=$2&subsubpage=$3 [L,QSA]

QSA 标志 是自动附加任何查询从原始 URL 到发送到 index.php 的查询字符串的字符串;如果您不需要该功能,可以将其删除。

This should do it:

RewriteEngine On

# First example
RewriteRule ^(.*)$ index.php?path=$1 [L,QSA]

# Second example
RewriteRule ^(.*)/(.*)/(.*)$ index.php?page=$1&subpage=$2&subsubpage=$3 [L,QSA]

The QSA flag is to auto-append any query string from the original URL to the query string sent to index.php; you can remove it if you don't need that functionality.

黯然 2024-12-30 15:14:54
RewriteRule (.*)?/ index.php?path=$1

这是第一个版本。

RewriteRule (.*)/(.*)/(.*)?/ index.php?page=$1&subpage=$2&subsubpage=$3

这是第二个。您始终可以使用此工具测试您的重写。

RewriteRule (.*)?/ index.php?path=$1

This is for the first version.

RewriteRule (.*)/(.*)/(.*)?/ index.php?page=$1&subpage=$2&subsubpage=$3

This is for the second one. You can always test your rewrites using this tool.

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