Rewrite Rule partially solved

Discussion in 'Server Operation' started by k1m0, Dec 18, 2013.

  1. k1m0

    k1m0 New Member

    Okay,
    So finally i was able to write my first rewrite rule

    RewriteRule ^(\w+)[/]*$ /profile.php?u=$1 [L]

    And its working great!!

    The above rewrite rule is for example.com / user it takes you to example . com / profile.php?u=user

    And for info: Add [R = 302, L] for redirect

    Now how can i rewrite the following

    example . com/user/events to example . com/events.php?u=user

    Anybody knows
     
  2. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    Try
    Code:
    RewriteRule ([^/]+)/events /events.php?u=$1 [L]
    
    If you want to really redirect (show the new url in the address bar of the browser) use R=301,L instead of L
     
  3. k1m0

    k1m0 New Member

    why are these things so complicated :)

    Thanks ofcourse.. but it seems not to be opening the page properly for some reason.. their is a call on body load of the events.php when i remove the rewrite rule all works well, otherwise it says call to undefined function in js

    RewriteRule ([^/]+)/events /events.php?u=$1 [L]

    any ideas?
     
  4. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    I assume in your html the js is loaded from relative path, so if your url is /userxyz/event the js is loaded from /userxyz/js/foo.js instead of /js/foo.js

    Try using absolute paths.
     
  5. k1m0

    k1m0 New Member

    thanks croydon,

    the absolute paths did work.

    some good tutorial needs to be written for the rewrite rule with good examples..
     
  6. k1m0

    k1m0 New Member

    Got another question relating to the first ReWrtie rule

    RewriteRule ^(\w+)[/]*$ /profile.php?u=$1 [L]

    if i use example.com/username/ it does not work example.com/username works perfectly. It was solved with the absolute path but just for info. Is there another solution for it in the regex above?
     
  7. k1m0

    k1m0 New Member

    Got it!!

    For future reference to anyone

    add

    Code:
    RewriteRule ^(.+)/$  /$1 [R=301,L]
    before

    Code:
    RewriteRule ^(\w+)[/]*$ /profile.php?u=$1 [L]
     

Share This Page