-1

Anyone please help me to redirect in apache webserver

My domains which have .co.in extensions

http://domain.co.in should be redirected to http://www.domain.co.in

Bastian Vs
  • 19
  • 3

3 Answers3

1

To rewrite just this domain:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.co\.in$ [NC]
RewriteRule ^(.*)$ http://www.domain.co.in$1 [L,R,QSA]

To rewrite for multiple domains in one rule:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}$1  [L,R,QSA]
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • The webpage at http://www.kalthura-expert.co.cc/ has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer. – Bastian Vs Jul 17 '11 at 14:55
  • @Bastian Vs on which? The single or multi-domain rule? You entered it exactly as above? It would behave that way if the `!` was omitted. – Michael Berkowski Jul 17 '11 at 15:17
  • @Basitan Vs are your domains setup as separate VirtualHosts in Apache,or are they ServerAlias to the same VirtualHost? – Michael Berkowski Jul 17 '11 at 15:18
1

create a .htaccess in the web root,

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.co.in [nc]
RewriteRule ^(.*)$  http://www.domain.co.in/$1 [R=301,L]
MCannon
  • 4,011
  • 2
  • 16
  • 12
  • Firefox has detected that the server is redirecting the request for this address in a way that will never complete. – Bastian Vs Jul 17 '11 at 14:54
  • thats odd, we've been using this in production environments on servers for years. I don't know what to suggest. – MCannon Jul 17 '11 at 15:19
  • @MCannon It has to be his Apache misconfiguration -- your rule is perfectly fine. – LazyOne Jul 17 '11 at 17:26
1

You do not need mod-rewrite complexity to do that, the most basic configuration will do the job better (simplier=better).

Make one Virtualhost, containing all domains to be redirected (one in ServerName the others in ServerAlias). Inside it use Redirect to the right one, where you use only one ServerName.

<VirtualHost *:80 />
   # catch all DNS to be redirected here
   ServerName redirect.domain.co.in
   ServerAlias domain.co.in
   ServerAlias domain.org
   ServerAlias domain_co_in.com

   Redirect permanent / http://www.domain.co.in/
</VirtualHost>

<VirtualHost *:80 />
    # The real VH with only one name
    ServerName www.domain.co.in
    (...)
</VirtualHost>
regilero
  • 29,806
  • 6
  • 60
  • 99