域根用户名 URL 的 ISAPI 重写 RewriteRule

发布于 2024-12-21 22:59:53 字数 385 浏览 1 评论 0原文

我正在尝试使用 ISAPI Rewrite 创建 root 用户名。

例如 www.mysite.com/myusername

我希望将其重定向到...

/user.asp=myusername

然后,如果找不到用户名,则根据 /folder/ 加载内容

也许最好检查一下文件是否存在存在folder.asp扩展名,如果不重定向到user.asp?username=folder

我知道简单的选择是只写.htaccess来引用:

www.domain.com/user/username

但我真的想要根URL吗?

提前致谢,

克里斯

I am trying to create a root username using ISAPI Rewrite.

E.g. www.mysite.com/myusername

I want this to redirect to...

/user.asp=myusername

Then if the username is not found to load content based on the /folder/

Maybe it would be good to check if a file with folder.asp extension exists and if not redirect to user.asp?username=folder

I know the easy option is to just write the .htaccess to reference:

www.domain.com/user/username

But I really want the root URL?

Thanks in advance,

Chris

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

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

发布评论

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

评论(1

缺⑴份安定 2024-12-28 22:59:53

我知道简单的选择是只编写 .htaccess 来引用:

我猜你的 Isapi Rewrite 模块是 Helicon 3.0
使用重写模块检查文件/文件夹是否存在比使用脚本语言更有效。
编写与您的用户名格式兼容的规则(有效字符等,请参阅注释)。
检查匹配的部分。如果文件/文件夹不存在,则进行重定向。

RewriteEngine On
# if the file does not exist
RewriteCond %{DOCUMENT_ROOT}/$1 !-f
# if the folder does not exist
RewriteCond %{DOCUMENT_ROOT}/$1 !-d
# from start to end, "^(\w+)[/]+$" only matches with one or more alphanumeric characters and "_".
# alternatively can end with one or more slashes.
# change [R = 302, L] to [L] if you want make a rewrite instead of redirect.
RewriteRule ^(\w+)[/]*$ /user.asp?username=$1 [R = 302, L]

I know the easy option is to just write the .htaccess to reference:

I guess your Isapi Rewrite module is Helicon's 3.0.
Checking file/folder existence using Rewrite Module is more efficient than using scripting language.
Write a rule that compatible with your username format (valid characters etc, see the comments).
Check the matched part. Make the redirect if it's not an exists file / folder.

RewriteEngine On
# if the file does not exist
RewriteCond %{DOCUMENT_ROOT}/$1 !-f
# if the folder does not exist
RewriteCond %{DOCUMENT_ROOT}/$1 !-d
# from start to end, "^(\w+)[/]+
quot; only matches with one or more alphanumeric characters and "_".
# alternatively can end with one or more slashes.
# change [R = 302, L] to [L] if you want make a rewrite instead of redirect.
RewriteRule ^(\w+)[/]*$ /user.asp?username=$1 [R = 302, L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文