Current location: Hot Scripts Forums » Other Discussions » Web Servers » htaccess - redirection-ish


htaccess - redirection-ish

Reply
  #1 (permalink)  
Old 03-07-07, 11:51 AM
jac2703's Avatar
jac2703 jac2703 is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
htaccess - redirection-ish

Hi all,

Question on .htaccess if i may..

I am wanting to redirect all requests on:

http://domain.com/userid/

to:

http://domain.com/index.php?uid=userid

i currently have:

Code:
RewriteEngine On
RewriteBase /
RewriteRule (.*) index.php?uid=$1
RewriteRule (.*)/ index.php?uid=$1
However this does not seem to work. I am not woried about any form of error checking as i will do this in index.php.

Do i need to edit index.php in any way?

Could anybody help?

Thank you

James
__________________
JamesCoyle.net Blog and Network tools.
Reply With Quote
  #2 (permalink)  
Old 03-07-07, 11:58 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Code:
RewriteEngine On
RewriteRule ^([\d]+)\/?$ index.php?uid=$1
Reply With Quote
  #3 (permalink)  
Old 03-07-07, 12:04 PM
jac2703's Avatar
jac2703 jac2703 is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Nico

Thanks for taking your time to help. Is there any chance you could just break down your post so i can understand each part? Sorry to bug you but too many people just want it done for them. I try to be the opposite.

Thanks again.

James
__________________
JamesCoyle.net Blog and Network tools.
Reply With Quote
  #4 (permalink)  
Old 03-07-07, 12:14 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Yes, sorry. Sometimes I'm lazy explaining.

Code:
^   - searches from the beginning from the string
(   - Opens a group (So we can catch the value and get it with $1
[   - Opens a new group. All characters in here are allowed. If it doesn't match here, it won't be rewritten.
\d  - \d stands for a unique numeric value.
]   - Closes the allowed characters group.
+   - If we don't put this it will only search for one number. The plus allows any length.
)   - Closes the first group
\/  - Stands for an escaped slash which we search for.
?   - Makes the previous character or group optional (The slash in this case)
$   - Searches from the end of the string.
Reply With Quote
  #5 (permalink)  
Old 03-07-07, 12:58 PM
jac2703's Avatar
jac2703 jac2703 is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks thats great!

The file doesnt seem to work however. If i enter http://domain.com/123/ i get a 404 error.
__________________
JamesCoyle.net Blog and Network tools.
Reply With Quote
  #6 (permalink)  
Old 03-07-07, 01:24 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
I just tested it locally, and it works just fine for me. Do you have the .htaccess file in the root directory?
Reply With Quote
  #7 (permalink)  
Old 03-07-07, 02:55 PM
bizzar528's Avatar
bizzar528 bizzar528 is offline
Community Liaison
 
Join Date: Sep 2004
Location: Pennsylvania, US
Posts: 1,550
Thanks: 2
Thanked 16 Times in 15 Posts
If your using a private server (not shared hosting) you also have to turn AllowOverride to All (in httpd.conf) instead of None... If that helps...
Reply With Quote
  #8 (permalink)  
Old 03-07-07, 03:35 PM
jac2703's Avatar
jac2703 jac2703 is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks both.

I am using shared hosting and mod_rw is enabled and working. Its weird because if i play about with it i do get some results but few desireable.

the file is in /home/username/public_html/subdomain_filder/.htaccess where the subdomain root is /home/username/public_html/subdomain_filder.

Are there any vairiations between versions? I am usint apache 1.3.x but am unable to find mod_rw version.

Now i am making the file correctly?! uploading a file with what you wrote above as the content (and nothing else). I am then calling the file ".htaccess". Is this correct? do i need to do anything to the index.php other than $_GET['uid']?

Thank you.

James
__________________
JamesCoyle.net Blog and Network tools.
Reply With Quote
  #9 (permalink)  
Old 03-07-07, 04:43 PM
jac2703's Avatar
jac2703 jac2703 is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
OK. So the following works as a test:

RewriteEngine On
RewriteBase /
RewriteRule $ index.php?uid=$1 [R]

i am re-directed to index.php?uid=

It seems to my the ^([\d]+)\/?$ part which it doesnt like. i will have another go tomorrow.
__________________
JamesCoyle.net Blog and Network tools.
Reply With Quote
  #10 (permalink)  
Old 03-07-07, 04:46 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Hm, I can't find anything wrong with it. The only idea I have is this:

Code:
^([\d]+)(/)?$
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CE7.net - Free forums, blogs, hosting & redirection! Domain contest - details inside! pcpp General Advertisements 1 11-02-11 07:15 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM
Search Engine URL: htaccess, dynamic php, & Frontpage ext. cebuy PHP 5 11-12-03 11:45 PM
htaccess client area mdittrich Script Requests 2 10-01-03 01:57 PM


All times are GMT -5. The time now is 01:25 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.