Page 1 of 1

redirecting urls

Posted: Thu Sep 25, 2003 1:47 pm
by kendall
Hello,

I have a situation where by i have a list of folders in a http://www.thedomain.com/thefolder

i want to have a functionality where if someone typed http://www.thedomain.com/somefolder it will redirect them to http://www.thdomain.com/thefolder/somefolder

the trick is here i want to fool people into thinking that there is a

http://www.thedomain.com/somefolder when really its http://www.thedomain.com/thefolder/somefolder

can this be done php? or is this a server situation?

Kendall

Posted: Thu Sep 25, 2003 1:53 pm
by Unipus
If you're on Apache, look at mod_rewrite. It will make you have happypants.

It could also be done with some ugly repetitive PHP code, I suppose, but I don't even really want to think about it... and spoofing the URL wouldn't be possible, anyway.

Posted: Thu Sep 25, 2003 2:07 pm
by Leviathan
I don't know how to do it on a server level, but for individual files (I use http://www.mikechase.ca/admin/ as a shortcut to http://www.mikechase.ca/admin.php), try this javascript:

Code: Select all

<script type="text/javascript">
<!--
&#123;
location="www.mikechase.ca/admin.php"&#125;
//-->
</script>

Posted: Thu Sep 25, 2003 2:40 pm
by kendall
Leviathan,

i don't think its really what i want...because there wouldn't be anything existing in the first place to plant a code...

Unipus,
do you think you can provide any links with documentation or proably expamples of similar done scenarios?

Posted: Fri Oct 03, 2003 12:40 am
by leebo
If you add:

RewriteRule ^folder1/ /folder1/folder2/ to your .htaccess

This will redirect any urls you need to, so for an example:

If your directory was http://www.thdomain.com/thefolder/somefolder
and wanted it to display content in http://www.thdomain.com/thefolder

you would add:

RewriteRule ^thefolder/ /thefolder/somefolder/ to your .htaccess

Hope this helps

Posted: Fri Oct 03, 2003 4:18 am
by JAM
Another idea is to use the header(). Often used on some boards, wher you have an /image/ directory that you dont want a user to see.
The /image/-dir contains a index.php that only hold something like

Code: Select all

<?php
 header("Location: ../");
?>
...or variables that are set earlier in an included file.

Posted: Fri Oct 03, 2003 8:39 am
by kendall
Leebo,

actually leebo it may be the other way round see i have a directory

http://www.thedomain.com/thefolder/somefolder
i want let say someone types http://www.thedomain.com/somefolder
it will lead them to the http://www.thedomain.com/thefolder/somefolder

thus
this is something i want to do with all folders residing in the '/thefolder'

Am i ridiculaous here or can it really be achieved?

JAM,

i am not really sure what you mean...because want i want will involve having the server find the real location of a folder...e.g.

as i said above if i have http://www.thedomain.com/thefolder/somefolder...the thing is i don't want people going thru the whole /thefolder/somefolder so i want them to just type root/somefolder and have the server figure it out that they want to really root/thefolder/somefolder. as in real life root/somefolder does not exist...however root/thefolder/somefolder does....am i making my self more clear here?

the reason i want this is that i am going to sub-host websites so i am putting all sub-host websites in a /thefolder/ but i don't want them to have there address as http://www..../thefolder/thewebsite....that's 2 long...so i'm thinking let them just have the http://www.../thewebsite.

Note: there is a reason that i need to have them in 'root/thefolder/thewebsite' rather than 'root/thewebsite'

Kendall

Posted: Fri Oct 03, 2003 10:18 am
by JAM
Well, in my example ../ is the same thing as the parent folder, hence mooving to a different host, using the same folder structure, will still lead you to the parent folder.

I'm not offering solutions, merely other ways to solve it, but you need to tweak them around abit yourselves, so that you learn, and so that it actually works in your code (that we have no idea of what it looks like).

To further elaborate the example:

Code: Select all

$url = 'www.example.com/foo/bar/example/sitename.php'; // example, can be taken from a $_SERVER variable.
$site = basename($url,'.php'); // sitename
header("Location: http://www.example.com/". $site ."/"); // forward user

Re: redirecting urls

Posted: Fri Oct 03, 2003 10:48 am
by McGruff
kendall wrote:Hello,

I have a situation where by i have a list of folders in a http://www.thedomain.com/thefolder

i want to have a functionality where if someone typed http://www.thedomain.com/somefolder it will redirect them to http://www.thdomain.com/thefolder/somefolder
Kendall
Pardon me for stating the obvious but why not just put the $somefolders in site root?

Posted: Fri Oct 03, 2003 12:19 pm
by kendall
JAM,

ok thanks...i was merely trying to comprehend what you were getting at....see the problem here is that

there is no variable to be passed
there isnt going to be any redirecting page

all im simply saying is this. lets say you build a website...you want to host it on my site

i give you http://www.mydomain.com/JAMwebsite

but the server directory is
root/websites/JAMwebsite
the url really is
now instead of someone typing
they can type
in there browser the end result being
http://www.mydomain.com/JAMwebsite redirects to http://www.mydomain.com/websites/JAMwebsites thus....www.mydomain.com/JAMwebsite directory structure is root/websites/JAMwebsite
McGruff,

the reason i am putting it in root/websites/JAMwebsite and not root/JAMwebsites/

is because i am building a kind of 'community thing' and want to devise some dynamic functions that interact with the server alot...also want to try keeping it together...its a bit hard to explain but im thinking if i shud have the website hosted in a root/websites/ rather than have it at the root