Forum Moderators: phranque

Message Too Old, No Replies

Redirect to external domain

         

mdesign

4:43 pm on Feb 8, 2006 (gmt 0)

10+ Year Member



Hi all..
this is my first message.

I need to redirect this type of links

www.mysite.it/ext/www.externalsites.it/etc-etc

to

http://www.externalsites.it/etc-etc

This RedirectMatch doesn't work

RedirectMatch ^ext/(.*)$ http://$1 [L]

Can you help me?

Tnx

[edited by: jdMorgan at 5:22 pm (utc) on Feb. 8, 2006]
[edit reason] De-linked. [/edit]

jdMorgan

5:19 pm on Feb 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mdesign,

Welcome to WebmasterWorld!

The RedirectMatch directive does not use the [L] flag, so that is a syntax error.


RedirectMatch ^/ext/(.*)$ http://$1

See Apache mod_alias [httpd.apache.org] and mod_rewrite [httpd.apache.org].

Jim

mdesign

8:45 pm on Feb 8, 2006 (gmt 0)

10+ Year Member


Thanks a lot jdMorgan!

Now it works, and I've improved the code

RedirectMatch ^/(http\://)?(www\..*)$ http://$2
RedirectMatch ^/(http\://)(.*)$ http://$2

By this code Apache send

http://www.mysite.com/http://www.domain.com or
http://www.mysite.com/www.domain.com or
http://www.mysite.com/http://domain.com

to the external url.

Do you think the syntax is good?

Sorry, my English is bad.

Mario.

jdMorgan

9:07 pm on Feb 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or you could use one directive for all of them:

RedirectMatch ^/(http\://)?(www\.)?(.+)$ http://www.$3

Jim

mdesign

9:13 pm on Feb 8, 2006 (gmt 0)

10+ Year Member



Ok Jim,
grazie!

Mario

mdesign

10:05 pm on Feb 8, 2006 (gmt 0)

10+ Year Member



..but I'm thinking that using your solution all the urls will be redirected to [$3...]
(example: www.misite.com/folder become [folder)...]

And if the external domain doesn't begin with www, the redirect will not work.
(example: a virtual subdomain [sub.domain.com)...]

I've written this redirects

RedirectMatch ^/(http\://)?(www\..+)$ [$2...]
RedirectMatch ^/(http\://)(.+)$ [$2...]

:)

- Edit -
I can't remove the links!

jdMorgan

1:21 am on Feb 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the URL-part that the back-referenced variables match are missing, they will simply contain nothing. $1 and $2 will always exist, even if they are 'blank'.

Test the code and see..

Jim

mdesign

11:34 am on Feb 9, 2006 (gmt 0)

10+ Year Member



Jim,
I've tested your code. If I try to open the homepage of the site and FF says:

Indirizzo non trovato.
Firefox non riesce a contattare il server www.index.php.

"Url not found.
Firefox can't contact the server www.index.php"

I don't look for a redirect of all the pages, but only of the link written in the format
[mysite.com...] similar)

Anyway my code works fine

jdMorgan

3:17 pm on Feb 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, that's odd...

I suppose you could also try:


RedirectMatch ^/(http://www\.¦www\.¦http://)(.*)$ http://www.$2

for a one-line solution.

Change the broken pipe "¦" character above to a solid pipe before use; Posting on this board modifies that character.

Jim

mdesign

4:10 pm on Feb 9, 2006 (gmt 0)

10+ Year Member



but with your code, the link
[site.com...]

shall be redirected to

http:// www. sub.site.com

check this two addresses
[posizionamento.minidesign.it...]
[posizionamento.minidesign.it...]

The first one doesn't work! For this reason I must specify two different rules.

Probably my 2-line solution is necessary. What do you think?

Thanks for the discussion. ^_^