ISAPI如果存在.ext的文件,则重写,然后将其作为文件夹URL

时间:2011-12-19 09:45:27

标签: asp-classic url-rewriting isapi-rewrite

我正在尝试做以下事情......

如果存在名为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

1 个答案:

答案 0 :(得分:0)

尝试使用:

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]