Page 1 of 1

URL Rewriting

Posted: Fri Feb 04, 2005 8:42 am
by mzfp2
Hi,

I'm need of rewriting urls that a user may browse to (which would be a invalud url), and rewrite the url to a valid url.

for instance a user may browse to :
http://www.alljammin.com/my_username

and thr url should be rewritten to maybe

http://www.alljammin.com/php/profiles.p ... y_username

my_username would be a user defined name, so it could be anything.

Im completely new to url rewriting, and regular expressions, so all your help will be greatly appreciated.

Kind Regards
Musaffar

PS, I'm hosting on a Apache webserver

Posted: Fri Feb 04, 2005 8:51 am
by feyd
have you read through all the threads we've had on mod_rewrite?

Posted: Fri Feb 04, 2005 10:12 am
by mzfp2
Hi

Thanks for your reply, I have read some of the posts, and they seem confusing, so Im looking for guidance specific to my problem.

Kind Regards
Musaffar

Posted: Fri Feb 04, 2005 10:34 am
by feyd
viewtopic.php?t=28701 has several details pertaining to this. In fact, everything involving mod_rewrite in the thread (sans spelling errors) works toward your "issue".. you will have to incorporate several of the posted bits together to achieve it, but the information is all there.

Posted: Wed Feb 09, 2005 3:02 am
by mhenke
Hey mzfp2,

I know how hard it is to understand mod_rewrite, it took me days to read up on it and I STILL wasn't able to write a basic redirect that worked :(

Unless you are going to use mod_rewrite for lots of stuff, there's no point studying it, as it's very complicated.

You asked for the most basic redirect, here it is:

Code: Select all

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -f їOR] 
RewriteCond %{REQUEST_FILENAME} -l їOR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.* - їL] 
RewriteRule ^(їa-z0-9]+)/? profiles/?id=$1 їL]
It checks for existing files and folders, then stops if it found one, if not it redirects. If you want to know how it works, or need to tweek it, you will still have to get back to the books ;)

Also try this site:

http://www.modrewrite.com

While studying mod_rewrite I mostly found others with the same question. I hope this snippet will free the real gurus from answering this basic question.