Welcome to WebmasterWorld Guest from 54.147.16.12

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

URL Parsing with PHP / Apache?

stripping URL information as parameters

     
8:05 pm on Jun 2, 2004 (gmt 0)

New User

10+ Year Member

joined:June 2, 2004
posts:4
votes: 0


I am coming up with a new site, which will be community-driven and subscription-based. I would like for people to go ato a URL that is friendly and easy to remember.

Let's say my domain is mydom.com. I am a new user who just registered newsite as my name. I want to load a PHP file, but call it something other than - say - default.php. In other words, I want to load a pagedefault.php file which will pull information from a database based on the user's name. There are not going to be user directories. (The user will have no ability to upload using FTP.)

As I currently see it, I can do something like: [mydom.com...]

What I'd like to do is something like:
[mydom.com...] on the address bar of the browser. This will be parsed into the correct parameter (username=newsite) and the correct page (default.php) will be loaded. I noticed one semi-related item here from a bit ago..

www.webmasterworld.com/forum88/421.htm

This forum post describes the use of MOD_REWRITE.

Ideas?

9:58 pm on June 2, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 12, 2003
posts:454
votes: 0


MOD_REWRITE os definately the way to go

make a file called .htaccess (nothing before the period)

Code:
RewriteEngine on
RewriteCond %{REQUEST_URI}!-d
RewriteRule (.*)/(.*).htm $2.php?username=$1

this will take

site.com/anything/something.htm

and send it to

site.com/something.php?username=anything

as long as anything isn't the name of a directory

example:
site.com/MyUsername/SomePage.htm
to
site.com/SomePage.php?username=MyUsername

HOPE THIS HELPS

9:59 pm on June 2, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 12, 2003
posts:454
votes: 0


add a space between } and ! the server software removes it out of the forum

also this post should have been made in the Apace Forum [webmasterworld.com]...for future reference

10:59 pm on June 2, 2004 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12548
votes: 2


Welcome to WebmasterWorld, filesiteguy!

WhosAWhata is referring to the Apache Module mod_rewrite [httpd.apache.org]. You can read some about it there and there is also an Apache URL Rewriting Guide [httpd.apache.org] that may come in handy.

Lastly, for a quick start, there is a good document in the WebmasterWorld Apache Forum titled:
An Introduction to Redirecting URLs on an Apache Server: For mod_rewrite beginners [webmasterworld.com]

11:03 pm on June 2, 2004 (gmt 0)

New User

10+ Year Member

joined:June 2, 2004
posts:4
votes: 0


Oh cool! It can be done with .htaccess files.

I kind of "flipped a coin" as to where to post.

You can see an early test here of me changing .html into php files using the .htaccess...

I'll see about how the suggestion worked.

Thanks!

[edited by: jatar_k at 11:04 pm (utc) on June 2, 2004]
[edit reason] no personal urls thanks [/edit]