asp-classicurl-rewritingseoisapi-rewrite

ISAPI Rewrite RewriteRule for domain root username URLs


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


Solution

  • 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+)[/]+$" 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]