使用 mod_rewrite 的 .htaccess 新手问题

发布于 2024-12-24 01:51:08 字数 406 浏览 1 评论 0原文

我需要为我的网站创建 SEO 友好的 URL。我发现我可以使用 .htaccess 来重写它们。所以我尝试了这个:

> http://www.domain.com/page/1/mypage
> http://www.domain.com/user/2/myuser
> http://www.domain.com/help/3/myhelp

现在我陷入了一个共同的规则,我不明白Ant根据页面名称重定向流量:

我使用:

RewriteEngine ON
RewriteRule ^(.*)$ page.php?page=$1

然后在我的PHP中我没有正确获取页面,我得到了文件是错误的。

我该如何解决这个问题?

I need to create SEO-friendly urls for my site. I found out I can use .htaccess to rewrite them. So I tried this:

> http://www.domain.com/page/1/mypage
> http://www.domain.com/user/2/myuser
> http://www.domain.com/help/3/myhelp

Now I am stuck with a common rule and I don't understand Ant to redirect traffic based on the name of the page:

I use:

RewriteEngine ON
RewriteRule ^(.*)$ page.php?page=$1

Then in my PHP I don't get the page correctly, I get the file which is wrong.

How can I fix this?

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

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

发布评论

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

评论(1

海夕 2024-12-31 01:51:08

以下是您需要执行的操作:

RewriteEngine On
RewriteBase /
RewriteRule ^([a-z_\-]+)/([0-9]+)/([a-z_\-]+)/?$ page.php?page=$1&id=$2&name=$3 [NC,L]

NC(或 nocase)使测试用例不敏感,A = a;

L(或最后)最后一条规则。在此停止重写过程,不再应用任何重写规则;

您可以在 http://httpd.apache.org/docs/current 获取更多信息/mod/mod_rewrite.html

Here's what you need to do:

RewriteEngine On
RewriteBase /
RewriteRule ^([a-z_\-]+)/([0-9]+)/([a-z_\-]+)/?$ page.php?page=$1&id=$2&name=$3 [NC,L]

NC (or nocase) Makes the test case-insensitive, A = a;

L (or last) Last rule. Stop the rewriting process here and don't apply any more rewrite rules;

You can get more info at http://httpd.apache.org/docs/current/mod/mod_rewrite.html

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