我如何避免并允许 htaccess 中的子目录

发布于 2024-09-29 19:20:50 字数 497 浏览 1 评论 0原文

.htaccess以下网址

http://www.mydomain.com/user.php?id=username

我希望通过

http://www.mydomain.com/username

...

我也想避免子目录名称冲突... 我有一个重写规则,

RewriteRule ^home/$ home.php?id=$1 [NC,L]

即我的网址变为 http://www.mydomain.com/home/ 所以我希望这个家被忽略......在 http://www.mydomain.com/username

I want the following url

http://www.mydomain.com/user.php?id=username

to

http://www.mydomain.com/username

via .htaccess...

i also want to avoid subdirectory name conflict....
where i have a rewrite rule i.e

RewriteRule ^home/$ home.php?id=$1 [NC,L]

so my url become http://www.mydomain.com/home/
so i want this home to be ignored...in http://www.mydomain.com/username

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

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

发布评论

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

评论(1

我一直都在从未离去 2024-10-06 19:20:50

重写规则按照它们出现的顺序进行评估。因此,只需将您的主目录重写规则放在第一位,然后将您的用户名重写规则放在第二位,如下所示:

RewriteRule ^home/(.*)$ home.php?id=$1 [NC,L]

RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^user.php$ $1 [NC,L]

Rewrite rules are evaluated in the order they appear. So just put your home rewrite rule first, and your username rewrite rule second, like this:

RewriteRule ^home/(.*)$ home.php?id=$1 [NC,L]

RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^user.php$ $1 [NC,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文