Apache .htaccess 规则冲突

发布于 2024-12-08 12:19:15 字数 985 浏览 1 评论 0原文

我正在开发一个网络应用程序,人们可以在其中创建个人资料。他们的个人资料存储在:app/user/UserName。我希望 URL 是这样的:app/UserName 但不能,因为我已经设置了 url:app/CategoryName/StoryName,其中有很多类别,如技术、时尚等。这是我的 htaccess 内容:

Options +FollowSymLinks
RewriteEngine on
ErrorDocument 404 /ef12/error/404.html
RewriteRule user/(.*)/ u.php?name=$1
RewriteRule user/(.*) u.php?name=$1
RewriteRule (.*)/(.*)/ scoop.php?cat=$1&title=$2
RewriteRule (.*)/(.*) scoop.php?cat=$1&title=$2
RewriteRule (.*)/ scoop.php?cat=$1
RewriteRule (.*) scoop.php?cat=$1

我想要用户的个人资料显示为:

app/AbhishekBiswal

和故事显示为:

app/technology/steve-jobs

我知道这是可能的:示例 > Twitter:twitter.com/Abhishek_Biswal 和 twitter.com/about,前者是个人资料,后者是关于 Twitter 的页面。

是的,我还有登录和注册等目录( http://app/Login ),这也与规则,也就是说,当我尝试访问 Login 目录时,服务器假定 Login 作为用户名(当我将配置文件 url 设置为 http 时: //应用程序/用户名中htaccess )并显示“无配置文件”错误。

谢谢。

I am developing a web app where people can create profiles. Their Profile is stored at: app/user/UserName. I want the URL to be like this: app/UserName but can't because I have already set the the url : app/CategoryName/StoryName where there are lots of Categories like Technology, Fashion, etc. Here's my htaccess content:

Options +FollowSymLinks
RewriteEngine on
ErrorDocument 404 /ef12/error/404.html
RewriteRule user/(.*)/ u.php?name=$1
RewriteRule user/(.*) u.php?name=$1
RewriteRule (.*)/(.*)/ scoop.php?cat=$1&title=$2
RewriteRule (.*)/(.*) scoop.php?cat=$1&title=$2
RewriteRule (.*)/ scoop.php?cat=$1
RewriteRule (.*) scoop.php?cat=$1

I want the User's Profile To Appear Like:

app/AbhishekBiswal

and stories to appear like:

app/technology/steve-jobs

I know it's possible: example > Twitter: twitter.com/Abhishek_Biswal and twitter.com/about where the former is a profile and the latter is a page about Twitter.

And Yes, I have also got Directories like Login and SignUp ( http://app/Login ), which also Conflicts with the Rules, that is, when I try to access Login directory, the server assumes Login as the UserName ( when I have set the profile url as http://app/UserName in htaccess ) and a "No Profile" Error is shown.

Thank You.

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

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

发布评论

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

评论(1

所谓喜欢 2024-12-15 12:19:15

在规则之前添加这些行。如果存在与 URL 匹配的文件或目录,它们会阻止规则生效:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Add these lines before the rules. They prevent the rule from taking effect if a file or directory exist that match the URL:

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