LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-20-2005, 07:31 AM   #1
basher400
Member
 
Registered: Mar 2005
Posts: 51

Rep: Reputation: 15
redirections between directories/files


hi

I am not sure this is a unix question but here goes:

lets say I have 2 folders "folder1" and "folder2"
they are accessed via web as so:
http://mydomain.com/folder1/
http://mydomain.com/folder2/


they both have an index.html file.

I want everybody that tries to access http://mydomain.com/folder1/ to be redirected to: http://mydomain.com/folder2/

how do I do it without using hard link like
Code:
ln folder2 folder1
?

I tried to use symbolic link as so:
Code:
ln -s folder2 folder1
and

Code:
ln -s folder2/index.html folder1/index.html
but of course it didn't work (got: folder or file already exsits)

what other options do I have in linux/unix?


thanks
 
Old 06-20-2005, 08:33 AM   #2
J_K9
Member
 
Registered: Nov 2004
Distribution: Slackware 11, Ubuntu 6.06 LTS
Posts: 700

Rep: Reputation: 30
Well, if you want to redirect an html page to another html page, then add this to the source code:
Code:
<html>

<head>
<title>Redirect Script</title>

<SCRIPT LANGUAGE="JavaScript">

<!-- begin hiding JavaScript from old browsers

		function redirect(){

			parent.location.href="http://www.google.com"

		}

// End hiding JavaScript -->

</SCRIPT>


</HEAD>

<body bgcolor="#ffffff" text="#000000" link="#8000ff" vlink="#808080" alink="#ff0080">

<h1 align="center">Redirect</h1>

<p>You will be redirected to the new page automatically. </p>

<p>If you are not redirected to the new page within 5 seconds, then please <a href="http://www.google.com">click here</a>.</p>


<SCRIPT LANGUAGE="JavaScript">

<!-- Hide script from old browsers

// set timeout to redirect after 1 seconds

		setTimeout("redirect()",10)

//-->

</SCRIPT>	

</body>

</html>
Obviously, change the "http://www.google.com" bit to link to your web page.

J_K9
 
Old 06-20-2005, 08:47 AM   #3
basher400
Member
 
Registered: Mar 2005
Posts: 51

Original Poster
Rep: Reputation: 15
thanks but things like that I know how to do.

I need to do something on the server side and without editing the index.html files.
 
Old 06-20-2005, 10:48 AM   #4
jcspray
Member
 
Registered: Mar 2004
Location: York, UK
Distribution: Ubuntu
Posts: 132

Rep: Reputation: 15
If you want people going to folder1 to go to folder2, then it doesn't make sense for folder1 to actually exist, does it? So to allow you to create a symbolic link called folder1, the existing folder called folder1 must be deleted or moved away.

mv folder1 folder1.bak
ln -s folder2 folder1
 
Old 06-21-2005, 04:26 AM   #5
basher400
Member
 
Registered: Mar 2005
Posts: 51

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by jcspray
If you want people going to folder1 to go to folder2, then it doesn't make sense for folder1 to actually exist, does it? So to allow you to create a symbolic link called folder1, the existing folder called folder1 must be deleted or moved away.

mv folder1 folder1.bak
ln -s folder2 folder1
no, you see, I have to temporarily make this redirection...
after a while I will un-redirect it
 
Old 06-21-2005, 04:35 AM   #6
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
The best way to do that is to configure Apache (or whatever your server is) to do the redirection.
The next best solution is to do this with PHP (for example), hence on the server side, by creating a folder1/index.php file, whose content is something like:
Code:
<?php
header('Location: http://'.$_SERVER['HTTP_HOST'].'/folder2/index.html');
exit(0);
?>
Else, there's Javascript as the previously mentionned fallback solution.

Yves.
 
Old 06-21-2005, 06:33 AM   #7
hardcorelinux
Member
 
Registered: Jan 2005
Location: India
Distribution: RHEL,CentOS,SUSE,Solaris10
Posts: 183

Rep: Reputation: 31
make a .htaccess file and

insert following code to it

Redirect /folder1/index.html http://yourdomain.com/folder2/

save it as .htaccess and put it in folder1, this will redirect all the requests to folder2
 
Old 06-21-2005, 07:49 AM   #8
basher400
Member
 
Registered: Mar 2005
Posts: 51

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by hardcorelinux
make a .htaccess file and

insert following code to it

Redirect /folder1/index.html http://yourdomain.com/folder2/

save it as .htaccess and put it in folder1, this will redirect all the requests to folder2
that's good advice but my serveradmin (yep, its not my, I'm just a webmaster ) says we don't have apache on server and can't do .htaccess
 
Old 06-21-2005, 08:26 AM   #9
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
Hmm...
Redirecting means telling the browser he should go to some other place than the one he is currently looking at. Key words here are "telling the browser".

Telling the browser something can be done by javascript or php or .htaccess or whatever your server supports (which one do you have, anyway?)

By creating symbolic links, you will never be able to tell the browser anything. It's just fundamentally impossible. All you can achieve by using symbolic links is telling the server (keyword: "server") that it should feed to the browser a file that is not in the current directory, but somewhere else. The browser, however, will never notice this. As far as it knows, the file it is getting is located at the 'old' location.

So in summary, these are fundamentally different things. You must decide which one best suits your needs.

Groetjes,

Kees-Jan

Last edited by kees-jan; 06-21-2005 at 08:27 AM.
 
Old 06-21-2005, 08:44 AM   #10
hardcorelinux
Member
 
Registered: Jan 2005
Location: India
Distribution: RHEL,CentOS,SUSE,Solaris10
Posts: 183

Rep: Reputation: 31
I thinki your question is


Quote:

lets say I have 2 folders "folder1" and "folder2"
they are accessed via web as so:
http://mydomain.com/folder1/
http://mydomain.com/folder2/

they both have an index.html file.

I want everybody that tries to access http://mydomain.com/folder1/ to be redirected to: http://mydomain.com/folder2/
This is a webserver related question i think, so i adviced that .htaccess

Quote:
Originally posted by basher400
that's good advice but my serveradmin (yep, its not my, I'm just a webmaster ) says we don't have apache on server and can't do .htaccess
Then which web server you are running ....
 
  


Reply


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CHMOD directories.sub-directories.files zerojosh Linux - Software 2 11-19-2005 03:22 PM
files and directories thanhVic Linux - Newbie 1 02-27-2005 04:04 PM
Copy files from different directories fiomba Linux - Software 3 02-11-2005 03:01 AM
Move certain files into different directories facets Programming 6 05-28-2004 01:20 PM
Number of files and directories ALF Linux - Software 4 06-11-2003 10:34 AM


All times are GMT -5. The time now is 09:39 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration