Grabbing URL Variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Grabbing URL Variable

Post by Zoram »

I have been curious about how to grab a certain part of a URL to use as a variable..,

For example on a URL: http://www.someSite.com/1523636 how would you grab the 1523636 to use? and what page would it be the index.php file that would do the grabbing?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

If you want it in that format then your going to have to use something like mod rewrite to transparantly write the query string. The query string is the ?mode=reply&t=42090 in the url. What mod rewrite will do is match a regex pattern of the url.. in your .htacess file you would have the following code to change http://domain.com/somepage

Code: Select all

RewriteEngine On
RewriteBase /

RewriteRule ^([A-Za-z]+)$  /index.php?page=$1
or

Code: Select all

RewriteEngine On
RewriteBase /

RewriteRule ^([A-Za-z]+)$ /$1.php
to http://domain.com/index.php?page=somepage or http://domain.com/somepage.php depending on which you used.
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post by Zoram »

so... if i make a subdomain... profile.site.com/42521 then change the .htaccess in the folder to the rewrite then i can use that subdomain as kind of easy linking... that's what i was looking for, thanks!
Post Reply