Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,162,754 members, 7,851,586 topics. Date: Wednesday, 05 June 2024 at 11:34 PM

Url Rewrite In Php - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Url Rewrite In Php (779 Views)

[ONLY] Bloggers With Less Than 15,000 Views? Daily Add Ur URL Let Me Help / Add More Than One Website Url To Your Twitter Account. / Add More Than One Website Url To Your Twitter Account. (2) (3) (4)

(1) (Reply) (Go Down)

Url Rewrite In Php by virtualn(m): 10:48am On Jul 28, 2010
Please how do i rewrite this url: http://www.site.com/members.php?userid=10 to something like http://www.site.com/seyi, so that when it is typed it shows the users profile.
Please help me with detailed infomation i know it has something to do with .htaccess and may be mod_rewrite if am not mistaken. Thank you
Re: Url Rewrite In Php by DualCore1: 11:40am On Jul 28, 2010
While you sort out the mod-rewrite and htaccess thingy, here's what i'm thinking of.

Create a database having the following info.
alias = which in your case will be "seyi". i.e the sub directory after the main domain.
member_id = which for "seyi" will be "10"

both fields must be unique

Now write a script to do the following.

Get the sub directory from a url when a user enters the url. So if the user enters http://www.site.com/seyi, get the "seyi" part of url and store in a variable $alias.

Crosscheck the variable with the list of alias u have in your database. If one row is affected, return the member_id for that row and store as $member_id

then use the php header method to redirect the user

header("Location: http://www.site.com/members.php?userid=".$member_id);


Aight I just wrote this here without testing it so if it works, fine. If it doesnt work  tongue
Re: Url Rewrite In Php by craziest: 1:35pm On Jul 28, 2010
kohana PHP framework makes this sweet, It supports url rewriting. Move ur app and enjoy!!!!

check http://docs.kohanaphp.com/
Re: Url Rewrite In Php by Nobody: 4:07pm On Jul 28, 2010
A professional way of doing it is to use the url rewriting of apache (if you are using an apache server).
You may enter "url rewriting tutorial" in google and go through the results.

But let me quickly give you some important points:
1. url rewriting will involve you creating a .htaccess file into your site
2. If you are using an offline server like wamp server, you may need to enable url rewriting in your apache config
3. this stuff works on some windows server.

I can answer any of your questions on url rewriting, but your question has to be specific. I dont know the server
you are using, so i cannot solve your question diectly at the moment.
Re: Url Rewrite In Php by Nobody: 5:05pm On Jul 28, 2010
you can make use of .htaccess but pratice locally i have bleeped up a website to that you enable the mod_rewrite engine and you specify what you want which reminds me you need to familair with regular expression e.e(^[a-zA-Z0-9]$) trust me it aint easy then u might have issues with css rendering so u might want to links ur css with the full name e.g http://domain/folder/*.css take care

(1) (Reply)

Challenge To Ethical Hackers / Website For Sale / Free Internet Website Lessons And Running Successsful Online Business-lesson One

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 20
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.