Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Redirecting subdirectories and subdomains to a PHP script
Old 11-14-2005, 07:04 AM Redirecting subdirectories and subdomains to a PHP script
Junior Talker

Posts: 3
Trades: 0
Hi all, hope you can help me.

If a user keys in a url such as:

www.mydomain.com/foobar

assuming the directory foobar does not exist, is it possible to direct this to a PHP script, which will take the "foobar" part as a variable? I realise I can get the path from the $SERVER global, but unaware of how to redirect - I guess it may be possible with a custom "404" page?

Also, the same question with a url such as www.foobar.mydomain.com

Thanks in advance for all your help!
MrShed is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-14-2005, 12:22 PM
lurkingfridge79's Avatar
Novice Talker

Posts: 9
Trades: 0
Correct me if I'm wrong, oh learned ones, but it seems to me like you'd be correct in using a custom 404 page. One way of redirecting (may favourite but others may disagree) is by using <meta> HTML tags. Specifically, it would look like this:

<META http-equiv="refresh" content="time;URL=URL">

Where time (the first content argument) is the time after the page loads, in seconds, to redirect the user, and URL, of course, being the URL of the webpage to redirect to. Also, subdomains are usually also linked to folders in the HTTP root of your website... meaning if a user tries to get to http://sub1.yourdomain.com it would be the same as trying http://yourdomain.com/sub1 .

So in short, use $SERVER to find the bogus directory being accessed, pass it through your redirection mechanism (probably attaching it to the URL as a query with ?), and ta-da!

Hope that helps some... and somebody correct me if I'm wrong

~Fred
lurkingfridge79 is offline
Reply With Quote
View Public Profile
 
Old 11-14-2005, 06:19 PM
Junior Talker

Posts: 3
Trades: 0
Thank you lurkingfridge most helpful. Two questions:

1) Is it possible to make a custom 404 page a php page? As although your answer is most informative, I still can't exactly see how I will get the path part, as won't it be lost after the change of page due to the redirect?

2) Dumb question....but how do you make a custom 404 page :| is it just "404.html" in the web root?

Thanks again

*EDIT* sorry 3 questions - to get the behaviour you describe with subdomains do you not have to set this up somewhere?
MrShed is offline
Reply With Quote
View Public Profile
 
Old 11-17-2005, 06:47 PM
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
I don't know the code, but you can create a .htaccess file to make it point to any file you want (for the 404).
feraira is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Redirecting subdirectories and subdomains to a PHP script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.78695 seconds with 12 queries