Writing Url redirection in centos

Hi All,

Please help me to write an url redirect condition in apache configuration. My requirement is to redirect all requests comes to http://site1.mysite.com to site2.mysite.com. i am using centos 7 server.

i have included "Redirect / http://site2.mysite.com " in site1.mysite.com configuration file, it is just showing home page of site2.mysite.com, but database is not getting updated…

Please help me in this issue.

The better way is to add the following Rewrite rule to root directory of old website (site1.mysite.com) under .htaccess file.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^site1.mysite.com RewriteRule (.*)
http://site2.mysite.com/$1 [R=301,L] 

@itz_sashi

Do one thing change your DNS records for redirecting your site

HI Ravi,

i have this content in my .htaccess file:

RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]

if i include your redirection rule, i am getting “Internal Server Error” . I am a bit confused in using .htaccess file. Could you please give a short description about .htaccess file,why and where do we use it exactly?

You doing wrong here, just create .htaccess in old site of apache root directory and add the following htaccess redirect rule.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^site1.mysite.com RewriteRule (.*)
http://site2.mysite.com/$1 [R=301,L]

and make sure to replace domains as per your requirements…

@itz_sashi

Once look at your configuration file httpd.conf under /etc/httpd/conf and change your Server Name for ex:-

<VirtualHost *:80>
ServerAdmin raghu@polytechnic.bh
DocumentRoot “/srv/http/polytechnic.bh”
ServerName polytechnic.bh
ServerAlias www.polytechnic.bh
ErrorLog “/var/log/httpd/polytechnic-error_log”
CustomLog “/var/log/httpd/polytechnic-access_log” common

change polytechnic.bh to other in your case it might be site1.domain.com change it to site2.doimain.com