redirecting urls
Moderator: General Moderators
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
redirecting urls
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
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
- Leviathan
- Forum Commoner
- Posts: 36
- Joined: Tue Sep 23, 2003 7:00 pm
- Location: Waterloo, ON (Currently in Vancouver, BC)
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">
<!--
{
location="www.mikechase.ca/admin.php"}
//-->
</script>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
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
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
...or variables that are set earlier in an included file.
The /image/-dir contains a index.php that only hold something like
Code: Select all
<?php
header("Location: ../");
?>- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
Leebo,
actually leebo it may be the other way round see i have a directory
http://www.thedomain.com/thefolder/somefolder
thus
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
actually leebo it may be the other way round see i have a directory
http://www.thedomain.com/thefolder/somefolder
it will lead them to the http://www.thedomain.com/thefolder/somefolderi want let say someone types http://www.thedomain.com/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
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:
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 userRe: redirecting urls
Pardon me for stating the obvious but why not just put the $somefolders in site root?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
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
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
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
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
the url really isroot/websites/JAMwebsite
now instead of someone typing
they can typewww.mydomain.com/websites/JAMwebsite // very long url
in there browser the end result beingwww.mydomain.com/JAMwebsite // more better
McGruff,http://www.mydomain.com/JAMwebsite redirects to http://www.mydomain.com/websites/JAMwebsites thus....www.mydomain.com/JAMwebsite directory structure is root/websites/JAMwebsite
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