Help with a Regular Expression for IIRF

Posted on 2011-05-05
Last Modified: 2012-05-11

I'm using IIRF 2.1 to handle my urls with IIS.

I'm trying to build a rule to access a particular page:

RULE: RewriteRule  ^/(\[a-z|A-Z|0-9]+)$ /subscribers/profile/?screenNameProfileView=$1

What should be the correct regex so the rule only consider usernames with these characters: A-Z, a-z, 9-0 and _, and avoid urls/usernames with /, ., and ?

Question by:HectorVazquez
    LVL 74

    Accepted Solution

    The vertical bars are literal (and redundant) inside your character class. You can safely trim the class to be:


    Open in new window

    which could also be represented by:


    Open in new window

    As a whole, try:

    RewriteRule  ^/(\w+)$ /subscribers/profile/?screenNameProfileView=$1

    Open in new window


    RewriteRule  ^/([a-zA-Z0-9_]+)$ /subscribers/profile/?screenNameProfileView=$1

    Open in new window

    and avoid urls/usernames with /, ., and ?

    I'm not sure what you mean here when you say "avoid."

    Author Comment

    Thanks, I didn't want that strings with dots or slashes be considered by the rule.


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
    Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now