views:

1020

answers:

1

I want to force a www. prefix on my website by using a .htaccess 301 redirect. I am currently trying:

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

Which normally works, but I am using Zend Framework which causes all requests to be redirected back to http://www.mysite.com/index.php regardless of the initial request.

For example...

http://mysite.com/blog, 
http://mysite.com/contact,
http://mysite.com/blog/this-is-my-article,

Will all be redirected to http://www.mysite.com/index.php

However, if I initially request a specific file, such as...

http://mysite.com/some-file.htm

The redirect works properly, redirecting to http://www.mysite.com/some-file.htm

+2  A: 

Hi,

In first time, don't forget to enable the rewriting ("RewriteEngine on"). The last line is important if you use Zend Framework.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
RewriteRule !\.(pdf|php|js|ico|txt|gif|jpg|png|css|rss|zip|tar\.gz)$ index.php

Now the url...

http://mysite.com/some-file.htm

... redirect to http://www.mysite.com/some-file.htm but use the index.php

Kevin Campion