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.

Website and Server Administration Forum


You are currently viewing our Website and Server Administration Forum as a guest. Please register to participate.
Login



Reply
Using "virtual directories" in a URL?
Old 02-01-2012, 06:24 PM Using "virtual directories" in a URL?
RadGH's Avatar
Skilled Talker

Posts: 76
Name: Radley
Trades: 0
So I've wondered for awhile what this is called, when you can link to a page that doesn't exist but use PHP (or maybe htaccess does it) to retrieve the URL and build a page based on it.

For instance, if I request "mywebsite.com/account/register", what would I have to do in order to manage the "register" part of this without actually having a folder called register?

I've seen websites do this, many blogging websites do this and store all kinds of data this way (/blog/2011/05/21/This_is_a_blog). What is it called? How is it done? Where should I go to read about this?

My theory would be to exploit a 404-error page, and turn around and give it a real page instead of an error. But I'm pretty sure that would still give the user a 404 error to their browser, which could cause problems. I don't know, just thinking out loud.

EDIT: I have many times before used GET methods to accomplish this, but it just seems clunky. I would like to use the directory method I tried to describe, and possibly still be able to use GET methods with it.

Last edited by RadGH; 02-01-2012 at 06:26 PM..
RadGH is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-01-2012, 07:09 PM Re: Using "virtual directories" in a URL?
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
This kind of thing is called mod_rewrite. You use it in .htaccess files.

Something like (not tested)
Code:
RewriteEngine On
RewriteRule ^account/(.*)$ account.php?action=$1
as your .htaccess file would allow something like mywebsite.com/account/register to work, because it's actually showing you mywebsite.com/account.php?action=register. With this example, it's taking whatever you put after account/ and 'showing' (not redirecting) you action.php?(string). So mywebsite.com/account/blahblah would 'show' you account.php?action=blahblah.

To use this as a '404' page, you'd find ErrorDocument useful.

Code:
ErrorDocument 404 404.php
I'll also be moving this to the Website and Server Administration board, where it's more at home
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!

Last edited by Physicsguy; 02-01-2012 at 07:14 PM..
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 02-01-2012, 10:50 PM Re: Using "virtual directories" in a URL?
vivekar's Avatar
Webmaster Talker

Posts: 612
Trades: 0
Quote:
Originally Posted by RadGH View Post
My theory would be to exploit a 404-error page, and turn around and give it a real page instead of an error. But I'm pretty sure that would still give the user a 404 error to their browser, which could cause problems. I don't know, just thinking out loud.

EDIT: I have many times before used GET methods to accomplish this, but it just seems clunky. I would like to use the directory method I tried to describe, and possibly still be able to use GET methods with it.
I would not advise to use a 404 php page to do this kind of redirection.
Instead of "404 Header", use 301 permanent redirect or 302 ( Temporary Redirect)
Use an intermediate page as physicsguy has given to do this kind of redirection.
__________________

Please login or register to view this content. Registration is FREE
(Active since 2003) |
Please login or register to view this content. Registration is FREE
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Old 02-02-2012, 07:07 AM Re: Using "virtual directories" in a URL?
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
As vivekar said, my solution will not just redirect. It keeps the URL the same, and no redirection happens behind the scenes. The server just 'serves' a different page. You can also use ErrorDocument 503 for server errors. Any HTTP Status code can be ErrorDoument-ed, but obviously some, like 200 OK, shouldn't be
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 02-02-2012, 06:19 PM Re: Using "virtual directories" in a URL?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,380
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I would not advise to use a 404 php page to do this kind of redirection.
Instead of "404 Header",
Why not??

You can make the "404" page return any HTTP status code you want.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Using "virtual directories" in a URL?
 

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 0.46846 seconds with 12 queries