开发者

Redirect with apache

开发者 https://www.devze.com 2023-03-28 07:45 出处:网络
I have a website with about 2000 links, and other site with the exact same pages. I need to know how to do in apache the redirect from one domain to the other one, taking into accounts that after the

I have a website with about 2000 links, and other site with the exact same pages.

I need to know how to do in apache the redirect from one domain to the other one, taking into accounts that after the .com the 开发者_运维问答page will be the same on both sites

Example User request: www.mydomain.com/product1

Should redirect www.mydomain2.com/product1

It should be a 301 redirect

Thank you for your help


This can easily be done with mod_rewrite:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

# redirect all requests to www.domain2.com domain
RewriteCond %{HTTP_HOST} =www.domain.com
RewriteRule .* http://www.domain2.com%{REQUEST_URI} [R=301,L]

This to be placed in .htaccess in website root folder (or into Virtual Host context) for www.mydomain.com. This also assumes that www.mydomain.com and www.mydomain2.com are on different servers / virtual hosts (in other words, not pointing into the same physical folder).


I do this at my company all the time. If you know how to use mod_rewrite, turn RewriteEngine on and use a RewriteRule with the [R] flag:

RewriteRule www.mydomain.com/product1 www.mydomain2.com/product1 [L,R]

See this site.

0

精彩评论

暂无评论...
验证码 换一张
取 消