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
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
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?
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.
thanks croydon, the absolute paths did work. some good tutorial needs to be written for the rewrite rule with good examples..
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?
Got it!! For future reference to anyone add Code: RewriteRule ^(.+)/$ /$1 [R=301,L] before Code: RewriteRule ^(\w+)[/]*$ /profile.php?u=$1 [L]