Gossamer Forum
Home : General : Internet Technologies :

Redirecting

Quote Reply
Redirecting
Hi

I have 3 directories on my server. They are now obsolete. When anyone requests any file within these directories I want them to be transferred to a new location.

What is the best way to do this? At the moment, I've got an index.html file in each with a redirect in the HTML. What other ways, if better, is there to do this? What about mod_rewrite?

- wil
Quote Reply
Re: [Wil] Redirecting In reply to
What you could do is simply use RedirectMatch in your .htaccess file (if your server is using Apache) to redirect to a "Moved" file like the following:

RedirectMatch /directory1 /errors/moved.html
RedirectMatch /directory2 /errors/moved.html
RedirectMatch /directory3 /errors/moved.html

OR just go to the new directory:

RedirectMatch /directory1 /newdirectory
RedirectMatch /directory2 /newdirectory
RedirectMatch /directory3 /newdirectory

Alternatively, you can use META REFRESH codes to go to the new directory. But this is not 100% reliable since it is client-dependent, meaning that the user would have to have Javascript enabled.

Of course, there are other solutions as well, like if you are using Cold Fusion, you can use a set of conditional statements that checks the script_name or path_name and then dynamically redirects the user to the new directory.

If you have dynamic web pages using Perl, you can also use CGI variables to check the location where the user has requested, and then redirect to the new folder.

In my opinion, the first set of codes would be the best.
========================================
Buh Bye!

Cheers,
Me

Last edited by:

Heckler: Apr 15, 2002, 9:53 AM
Quote Reply
Re: [Heckler] Redirecting In reply to
Hi Eliot:

I believe the directive Redirect_Match should be expressed as RedirectMatch (no underscore).



Cheers - Dan Cool

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] Redirecting In reply to
Or you could just use Redirect

Redirect /olddir /newdir

RedirectMatch is more for specific matches.

Last edited by:

Paul: Apr 15, 2002, 11:08 AM
Quote Reply
Re: [Paul] Redirecting In reply to
Yep. I was keeping my response simple. But yes, the RedirectMatch directive (equivalent to Redirect), but allows for the use of regex. So RedirectMatch is more tailored to specific matches, and therefore you could use Redirect in place of RedirectMatch in this case.



Cheers - Dan Cool

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln

Last edited by:

dan: Apr 15, 2002, 11:42 AM
Quote Reply
Re: [dan] Redirecting In reply to
Sorry that was me being lazy, it was supposed to be a reply to Eliot :)
Quote Reply
Re: [Heckler] Redirecting In reply to
>>
Alternatively, you can use META REFRESH codes to go to the new directory. But this is not 100% reliable since it is client-dependent, meaning that the user would have to have Javascript enabled.
<<

meta-refreshes are javascript?...I thought they were html :)

Last edited by:

Paul: Apr 15, 2002, 11:47 AM
Quote Reply
Re: [Paul] Redirecting In reply to
Yes, it does...
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Heckler] Redirecting In reply to
Sorry?..what does what?
Quote Reply
Re: [Paul] Redirecting In reply to
Well, Will specifically stated that he has three specific old directories that he wants to specifically redirect to a specific new directory, thus RedirectMatch is the better directive to use since he is dealing with specific set of directory parameters.

Tongue
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Heckler] Redirecting In reply to
You are misinterpreting "specific"

A directory redirect does not need to be specific as anything inside the directory needs to be redirected, hence Redirect is more suitable, although both work.

Redirect match is more appropriate if you wish to redirect individual files in a directory such as all gifs or all html for example:

RedirectMatch ^(foo\.gif)$ http://foo.com/$1

Last edited by:

Paul: Apr 15, 2002, 11:53 AM
Quote Reply
Re: [Paul] Redirecting In reply to
You say POTATO, I SAY POTATOE...Tongue

The fact is that either set of codes will work, why the hell argue with me all the time, PAUL! Mad
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Heckler] Redirecting In reply to
Well its how you choose to interpret it eliot.

Most people tend to see it as an alternative suggestion or advice...only you see it in a different way :)

As I pointed out, both code examples work, I wasn't claiming that yours didn't, its just that perhaps one is more suitable than the other, afterall thats why apache created two different directives...if they were both identical one would be pointless :)

Last edited by:

Paul: Apr 15, 2002, 11:56 AM
Quote Reply
Re: [all] Redirecting In reply to
Thank you all <g>...

I'm going to go with the Redirect or RedirectMatch or whatever it is. It sounds good as it keeps it all in one htaccess file in my root directory (presuambly??) so it's easier to manage and update. Is this right? No need to spread it across individual htaccess'es in each directory I need redirecting?

Cheers

- wil
Quote Reply
Re: [Wil] Redirecting In reply to
Yeah that should work fine...eg...

Redirect /dir1/ somewhere else
Redirect /dir2/ somewhere else
Quote Reply
Re: [Wil] Redirecting In reply to
Yes, just put the codes that I initially posted in my original reply in your ROOT .htaccess file.
========================================
Buh Bye!

Cheers,
Me

Last edited by:

Heckler: Apr 15, 2002, 1:29 PM
Quote Reply
Re: [Heckler,Paul] Redirecting In reply to
Thanks, guys!

- wil
Quote Reply
Re: [Wil] Redirecting In reply to
Hm.

Now this is a bit annoying. If I have my .htaccess looking like:

Code:
RedirectMatch /pr /en/pr
RedirectMatch /design /en/design

Then any request to /pr will be redirected accordingly. But any request to /pr/ will not be redirected as there's a trailing slash. What's the way around this one, apart from creating two entries for each dir?

- wil