Find the answer to your Linux question:
Results 1 to 7 of 7
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    mod_rewrite, need regex help

    Let me preface by saying that I am completely new to regular expressions and mod_rewrite.

    I've been looking around for a while and I haven't found anything posted that could help me specifically. Heres what I'd like:

    URL typed into browser:

    Rewritten URI

    Basically looking to have the initial URL be static, but with the possibility of a dynamic variable appended to the end.

    I know the basics of mod_rewrite from tutorials I've found online, but can't seem to figure out this specific problem.


  2. #2


    ?? maybe

  3. #3
    I tried something similar already with no luck. Gives me a 404.

    This is what i tried:

    RewriteRule ^user/(.+)/?(.*)$/ users.php?user=$1&$2

  4. $spacer_open
  5. #4

    RewriteRule ^(.*)user/(.+)/\?(.*)$ $1users.php?user=$2&$3

  6. #5
    Still no luck. Did you manage to get that working yourself?

  7. #6
    I'm getting close, but can't seal the deal.

    RewriteRule ^user/([^/\.]+)/refer=([^/\.]+)/?$ users.php?user=$1&refer=$2 [L]

    Is working for the example URI

    As soon as i try to add in the "?" character it fails and gives me a 404.

    RewriteRule ^user/([^/\.]+)/\?refer=([^/\.]+)/?$ users.php?user=$1&refer=$2 [L]

    any advice?

  8. #7
    My Regex worked fine for the example that you gave.

    In your example above, you need to ESCAPE the ? character, as ? is used in Regex to ask if there are 0 or 1 occurances.


    RewriteRule /^.*user/(\w+)/[\?](.*)$/ users.php?user=$1&$2

    That should move the username, and keep the rest of the URL intact, including after the "?"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts