Web Hosting Forum | Lunarpages
News: Server Migrations to San Diego: Deneb, Felix and Tsohea are moving to San Diego starting Tuesday, December 30, 2008 at 10pm Pacific. They will complete their moves Friday night, January 2, 2009

Isis, Seth and Ez-web-n-mail will move physically on Friday, January 2, 2009

Please see the forum posts at http://www.lunarforums.com/lunarpages_web_hosting_server_information-b54.0/

+ Submit Your Own Web Site for the January 2009 Site of the Month Contest!
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
January 07, 2009, 10:13:59 PM


Login with username, password and session length


Pages: [1]   Go Down
  Print  
Author Topic: Help with .htaccess and RegEx  (Read 767 times)
marvelous_mogli
Newbie
*
Offline Offline

Posts: 4


« on: March 05, 2007, 09:50:27 PM »

Hi,

I need help with URL Rewriting. I have page that shows the details of a user and is in a subfolder.

documentroot/subfolder/user.php

It needs a id to be passed in order to show the details of a user e.g. user.php?userid=AX-123

Now I would like to use SE friendly URLs of the kind http://mysite.com/user/AX-123

What code should I use to do this on a Lunar Pages shared hosting server? LP says mod_rewrite is enabled. It's Apache 1.3.x with PHP 4.4.x

Please help.
Logged
MrPhil
Quantum Encyclopedia Writer
*****
Offline Offline

Posts: 3573



« Reply #1 on: March 06, 2007, 10:25:03 AM »

Try the following:

RewriteEngine On
RewriteRule ^/user/([^/]+)$ /documentroot/subfolder/user.php?userid=$1


You may have to tweak it a bit... I haven't done this for a while... the pattern might be ^user... instead.
Logged

marvelous_mogli
Newbie
*
Offline Offline

Posts: 4


« Reply #2 on: March 08, 2007, 12:54:16 AM »

It's the this error when I tried http://gangarasa.com/user/1234/ No luck. can you help?

== Error
Not Found
The requested URL /user/1234/ was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

== .htaccess content
RewriteEngine on

RewriteRule ^/user/([^/]+)$ /hs/test.php?userid=$1


hs folder exists and test.php too exists

Logged
MrPhil
Quantum Encyclopedia Writer
*****
Offline Offline

Posts: 3573



« Reply #3 on: March 08, 2007, 08:34:55 AM »

OK, your rewrite was not done. The original /user/1234/ went through. You have a / on the end of the URL, which is causing it not to match your pattern. You can try changing your pattern:

RewriteRule ^/user/([^/]+)/?$ /hs/test.php?userid=$1

This says "Look for a URL (after the domain name) starting with /user/. Grab whatever follows, one or more characters, up to but not including a / and stick it into "$1". A / may optionally follow, and then the URL ends ($). Output a URL of /hs/test.php?userid= followed by whatever was saved in "$1".

Note that it is possible that the pattern will have to be tweaked to remove the first / (^user/...). Try that if it still doesn't match. Or, you could use ^/?user... to match either way. Also note: don't put [R=301] after the RewriteRule, as you don't want the browser or search engine to see that.

Go to cPanel > Error Pages and make yourself a 403.shtml and a 404.shtml (and 400, 401, and 500 if you want). That will get rid of the 404 Not Found error.
Logged

marvelous_mogli
Newbie
*
Offline Offline

Posts: 4


« Reply #4 on: March 08, 2007, 09:12:48 AM »

RewriteRule ^user/([^/]+)/?$ /hs/test.php?userid=$1

this one worked MrPhil thanks a buch.
Logged
MrPhil
Quantum Encyclopedia Writer
*****
Offline Offline

Posts: 3573



« Reply #5 on: March 08, 2007, 10:14:31 AM »

You're most welcome "a book"  Roll
Logged

marvelous_mogli
Newbie
*
Offline Offline

Posts: 4


« Reply #6 on: March 08, 2007, 10:24:35 AM »

Smile sorry typo

it was 'thanks a bunch' Smile
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM