0

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

Chris Dowdeswell
  • 858
  • 2
  • 11
  • 25

1 Answers1

0

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]
Andrew
  • 511
  • 3
  • 7