htaccess 动态用户名

发布于 2024-10-02 03:46:44 字数 399 浏览 1 评论 0原文

您好,我正在使用此代码作为我的子目录重定向用户名

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ profile.php?username=$1&%{QUERY_STRING}

我遇到这个问题,即用户输入domain.com/username/ 将会出现问题,只有当他们输入domain.com/username 时它才有效 有

任何解决方案吗?

另外,例如,如果我有一个真实的目录调用/images/,当它们进入domain.com/images时。关于某些循环问题将会出现错误。解决这个问题的方法是什么?

Hi i'm using this code for my subdirectories redirect for usernames

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ profile.php?username=$1&%{QUERY_STRING}

I have this problem that is user enter domain.com/username/ it will have problems, it only works if they enter domain.com/username

Any solutions to this??

Also, example if i have a real directory call /images/, when they enter domain.com/images. there will be an error regarding some looping problem. what is the way to solve this issue?

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

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

发布评论

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

评论(1

屋檐 2024-10-09 03:46:44

最好让您的重写需要尾部斜杠。

将非斜线结尾的网址重定向到斜线结尾的网址

然后您可以使用类似以下内容

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]

:我希望这会有所帮助。

It's better to make your rewrites require the trailing slash.

then you can redirect non-slash ended urls to slash ended one,

using something like this :

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]

I hope this helps.

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