logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Redirection to another domain
Author
profc



Joined: 04 Dec 2009
Posts: 1

PostPosted: Fri 04 Dec '09 11:07    Post subject: Redirection to another domain Reply with quote

Hi, I am newbie. I have a site: somesite.com And there is a subdirectory (somesite.com/newsite) which is linked to another domain: newsite.com

So the contents of newsite.com can be also available using url: somesite.com/newsite And I want to make a redirection from somesite.com/newsite(.*) to newsite(.*)

I tried this (in .htaccess in root directory):
Code:
RedirectMatch 301 /newsite/(.*) http://newsite.com/$1


But I got 302 Message (Found. The document has moved here.). It's because Apache made redirection if I used domain newsite.com too.

So I tried this:
Code:
RedirectMatch 301 http://somesite.com/newsite/(.*) http://newsite.com/$1
RedirectMatch 301 http://somesite.com/newsite/(.*) http://newsite.com/$1


And this:
Code:
RewriteRule http://somesite.com/newsite/(.*) http://newsite.com/$1 [R=301,L]
RewriteRule http://somesite.com/newsite/(.*) http://newsite.com/$1 [R=301,L]


But none of it does any effect.

What am I doing wrong? Or is there any other way to solve the problem? Thanks in advance.
Back to top
paranid



Joined: 02 Mar 2009
Posts: 11

PostPosted: Fri 04 Dec '09 13:00    Post subject: Reply with quote

Hi,
is it really necessary to use RedirectMatch (trying to play with regexes)?

It can be easier to use Redirect like:

Code:

Redirect permanent /newsite http://newsite.com


placed in somesite.com server setting/VirtualHost container.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7304
Location: Germany, Next to Hamburg

PostPosted: Fri 04 Dec '09 13:22    Post subject: Reply with quote

The redirect has the advantage that everything after the URL is also putted to the new url, not just the domain name.

I'm not an expert for rewriting, so I don't know how to put the 301 header into it, but rewrite the URL to the new server works like this

Code:

RewriteEngine On
RewriteRule (.*) http://newsite.com/%{REQUEST_URI}
Back to top


Reply to topic   Topic: Redirection to another domain View previous topic :: View next topic
Post new topic   Forum Index -> Apache