ISAPI 重写,如果带有 .ext 的文件存在,则允许它作为文件夹 URL

发布于 2024-12-21 19:01:38 字数 860 浏览 1 评论 0原文

我正在尝试执行以下操作...

如果存在名为 login.asp 的页面,则允许将其重写为 /login/ 但不允许直接访问 login.asp< /代码>。

到目前为止,这是我的代码。

# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.87

RewriteEngine On
# if file is not exists
RewriteCond %{DOCUMENT_ROOT}/$1 !-f

# if folder is not exists
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+)[/]*$ /username.asp?username=$1 [L]

因此,如果您想象用户输入 www.web.com/contact,如果有一个名为 contact.asp 的页面,它会显示重写的内容。如果 .asp 页面不存在,则会从 /user.asp?username=contact 加载内容以检查它是否是用户配置文件。

非常感谢!

C

I am trying to do the following...

If a page called login.asp exists then allow a rewrite for it as /login/ but do not allow a direct access to login.asp.

Here is my code so far.

# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.87

RewriteEngine On
# if file is not exists
RewriteCond %{DOCUMENT_ROOT}/$1 !-f

# if folder is not exists
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+)[/]*$ /username.asp?username=$1 [L]

So if you imagine the user types www.web.com/contact if there is a page called contact.asp it displays that rewritten content. If the .asp page does not exist then it loads the content from /user.asp?username=contact to check if it is a user profile.

Much appreciated!

C

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

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

发布评论

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

评论(1

热鲨 2024-12-28 19:01:38

尝试使用:

RewriteEngine On
# if reqiested url+.asp exists
RewriteCond %{REQUEST_FILENAME}\.asp -f
# if folder does not exist
RewriteCond %{REQUEST_FILENAME} !-d
Rewrite requested one-level url to target place
RewriteRule ^(\w+)/?$ /username.asp?username=$1 [NC,L]

Try using:

RewriteEngine On
# if reqiested url+.asp exists
RewriteCond %{REQUEST_FILENAME}\.asp -f
# if folder does not exist
RewriteCond %{REQUEST_FILENAME} !-d
Rewrite requested one-level url to target place
RewriteRule ^(\w+)/?$ /username.asp?username=$1 [NC,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文