LebGeeks Forums

A community for lebanese technology enthusiasts.

You are not logged in.

Announcement

Make sure you read the LebGeeks Forum Etiquette

#1 26-07-2010 01:39:19 pm

Asharif
Member
From: Tripoli, Lebanon
Registered: 23-07-2010

ModRewrite Help

hey all,
i have this problem, i know it will sound silly but it has been baffling me all day,
i am building what my boss calls "engine", which is primarly a single script with a different database for each user, the problem is that i need him to be redirected via the URL.
example:
if the user types www.mycompany.com/username
he should be redirected to www.mycompany.com/index.php?name=username
i have been playing all day with the file but nothing seems to work,
here is some of the code i've used so far,

Code:

RewriteRule ^test/([a-z0-9]+) http://www.myweb.com/test/index.php?name=$1 [PT]

Code:

RewriteRule (.*) /index.php?name=$1 [PT]

Code:

RewriteRule (.*) test/index.php?name=$1

any help.. anyone?

Last edited by Asharif (26-07-2010 01:50:46 pm)

Offline

 

#2 26-07-2010 08:49:31 pm

samer
administrator
From: Lebanon
Registered: 27-07-2004
Website

Re: ModRewrite Help

Try this:

Code:

RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?name=$1 [L]

Offline

 

#3 26-07-2010 10:46:45 pm

rolf
Member
From: Beirut
Registered: 05-04-2005

Re: ModRewrite Help

Thats the most basic use of mod_rewrite, there should be plenty of examples on google...
mod_rewrite is a pain to debug though, you need to build it very gradually and do

Code:

<pre>
<?php print_r($_GET) ?>
</pre>

in the PHP to better see what is happening.
There's a way to debug it but I never used it myself I think it's not very user-friendly.

EDIT: Start without the ^ at the beginning and with something very generic like (.*) to see the result in the php print_r, and build from there.

Last edited by rolf (26-07-2010 10:48:22 pm)


mpt.gov.lb : Sucking the fun out of Internet since 1990 !

Offline

 

#4 27-07-2010 08:45:26 am

Asharif
Member
From: Tripoli, Lebanon
Registered: 23-07-2010

Re: ModRewrite Help

Here is the code that eventually worked:

Code:

RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php?test=$1 [L]

thanks everyone :)

Offline

 

#5 27-07-2010 05:49:19 pm

samer
administrator
From: Lebanon
Registered: 27-07-2004
Website

Re: ModRewrite Help

Asharif wrote:

Here is the code that eventually worked:

Code:

RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php?test=$1 [L]

thanks everyone :)

You're welcome.
Always remember to turn the RewriteEngine on.

Offline

 

Board footer

(CC) 2004-2010 LebGeeks.com
Part of the LebGeeks Network.