1

I have wordpress site hosted on openshift say example.com. I am redirecting example.com to www.example.com (non www to www). I have created alias for www and non www version and updated my cname with app name.

I tried pointing non www cname record to www version and it was working except for homepage (same 301 redirect loop) so i reverted non www cname back to app url.

Now www version is serving but non www version is creating 301 redirect loop by redirecting to itself. My wordpress site url is www.example.com and i have not added any htaccess directives.

How can i properly redirect non www to www version.

2 Answers 2

3

I think there is some issue with openshift's php hosting. I found this thread on stackoverflow. So catch is you append port no after host. This .htaccess code should work.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com:80/$1 [R=301,L] 
0

In your htaccess add the following (before the WordPress rewrites):

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L] 

The above will make a permanent redirect from non-WWW to WWW.

Alternatively you can do this in Google Webmaster Tools. Also, make sure that you have the correct settings in your WP-Admin -> Settings -> General -> Site URL & WordPress URL.

3
  • Thanks but It is not working.
    – Harikesh
    Mar 1, 2015 at 14:58
  • Make sure you remove any redirects you might have in your DNS settings. Also, what's your Site URL: www.example.com or example.com? Mar 1, 2015 at 15:22
  • www.example.com
    – Harikesh
    Mar 1, 2015 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.