Mobile app version of vmapp.org
Login or Join
Kevin317

: Issue with Apache redirection I want to redirect mysite.com or http://mysite.com or www.mysite.com or any other format given my user to http://www.mysite.com, I'm able to achieve this by rewriting

@Kevin317

Posted in: #Apache2 #Htaccess #ModRewrite

I want to redirect mysite.com or mysite.com or mysite.com or any other format given my user to www.mysite.com, I'm able to achieve this by rewriting following lines in my .htaccess file

Rewritecond %{http_host} ^mysite.com
RewriteRule ^(.*) www.mysite.com/ [R=301,L]


But I want do this from Apache,So I've added following line in Virtual host conf file of the site and removed above two lines from .htaccess

Redirect 301 / mysite.com/

But whenever I'm trying to access the site following error is displyaing,

Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.


where I'm doing the wrong ?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Kevin317

2 Comments

Sorted by latest first Latest Oldest Best

 

@Nickens628

What you want is this:

RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) www.example.com/ [L,R]


which was copied directly from here. You really ought to read through that page and understand it.

Your current rewrite rule, as it stands, sends every request to a local server path that your apache config probably cannot deliver ('/' is the root directory of your server not the root of your website). Apache in turn will try to respond to that with an error page, which in turn gets redirected to the '/' again, hence an infinite redirect.

The above code only redirects requests NOT bound for example.com and preserves the rest of the URL when it redirects.

10% popularity Vote Up Vote Down


 

@Frith620

Your directive causes an infinite redirection loop.

The reason is that a 301 gets returned to the browser and that host and path are really separate things, despite forming a URL. When a browser sees a 301 redirect to site.com/ it interprets it as find site.com and ask for the / path from the standard HTTP port.

With your unconditional rule, which is valid for site.com, the 301 is returned again which sends them in an infinite loop.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme