mod_rewrite 用户 ID 错误

发布于 2024-12-13 06:31:09 字数 688 浏览 0 评论 0原文

我是重写 url 的新手,想知道如何重写

From this /个人资料/4

到此 /profile.php?id=4

到目前为止,我有此规则

RewriteRule ^profile/([0-9]+)/?$ profile.php?id=$1

,但它在浏览器中显示此内容

Firefox 已检测到服务器正在以永远不会完成的方式重定向对此地址的请求。

在浏览器地址栏中显示/profile/4/index.php,这是不正确的。

.htaccess 文件

<Files .htaccess>
order allow,deny
deny from all
</Files>

Options +FollowSymlinks
RewriteEngine on
#ErrorDocument 404 /test.php
DirectoryIndex test.php
RewriteRule settings editProfile.php
RewriteRule update update.php
RewriteRule home test.php
RewriteRule ^profile/([0-9]+)/?$ profile.php?id=$1

I'm new to rewriting urls and wanted to know how i would rewrite

From this
/profile/4

To this
/profile.php?id=4

I have this rule so far

RewriteRule ^profile/([0-9]+)/?$ profile.php?id=$1

but it displays this in the browser

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

It displays /profile/4/index.php in the browser address bar which is incorrect.

.htaccess file

<Files .htaccess>
order allow,deny
deny from all
</Files>

Options +FollowSymlinks
RewriteEngine on
#ErrorDocument 404 /test.php
DirectoryIndex test.php
RewriteRule settings editProfile.php
RewriteRule update update.php
RewriteRule home test.php
RewriteRule ^profile/([0-9]+)/?$ profile.php?id=$1

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

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

发布评论

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

评论(2

梦回梦里 2024-12-20 06:31:09

你已经差不多了。尝试使用这个,

RewriteRule ^profile/(.*)$ profile.php?id=$1

我在网上找到了这个很好的免费资源,可以帮助您在测试您的重写规则之前将它们发布到您的实时网站。这可能对未来有所帮助。看来您的规则应该像您发布的那样起作用。问题一定出在其他地方。

You are pretty much there. Try using this instead

RewriteRule ^profile/(.*)$ profile.php?id=$1

I found this good free resource online to help you test your rewrite rules before you post them to your live site. This may help for the future. It looks like your rule should work as you have it posted though. The problem must be somewhere else.

他是夢罘是命 2024-12-20 06:31:09

你的规则很好,所以有一个重定向与它相冲突。我想您在 /profile/4 处没有真正的目录,因此剩下的主要候选目录是 mod_negotiation。试试这个:

Options -MultiViews

Your rule is just fine so there's a redirection somewhere conflicting with it. I suppose that you don't have a real directory at /profile/4 so they main candidate left is mod_negotiation. Try this:

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