redirecting openshift rhcloud domain to custom domain for SEO purposes
.htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, redirects, mod-rewrite, , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :Openshift application url: example.rhcloud.com
Custom domain: example.com
I came across this link and added the redirection rule. However, I can not access example.rhcloud.com now. My custom domain is www.example.com.
To avoid duplicate content problems, I tried this redirection.
Here is my .htaccess file:
RewriteEngine on
# Uncomment the following lines to force HTTPS
#RewriteCond %HTTP:X-Forwarded-Proto !https
#RewriteRule .* https://%HTTP_HOST%REQUEST_URI [R,L]
# WordPress Defaults
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]
# Redirect Https traffic to Http
RewriteEngine on
RewriteCond %SERVER_PORT ^443$ [OR]
RewriteCond %HTTPS on
RewriteRule ^(.*)$ http://%HTTP_HOST%REQUEST_URI [R=301,L]
# Redirect non-www to www
RewriteEngine on
RewriteCond %HTTP_HOST !^www. [NC]
RewriteRule ^(.*)$ http://www.%HTTP_HOST/$1 [R=301,L]
# Redirect openshift rhcloud domain to custom domain
RewriteEngine on
RewriteCond %HTTP_HOST ^example.rhcloud.com$
RewriteRule (.*)$ http://www.example.com/$1 [R=301,L]
Why is example.com not redirecting to ww.example.com? How do I fix this?
Also, I see that since I have https to http redirection and non www to www redirection, my blog has been loading slow. How can I reduce it to lesser number of rules?
Edit:
In Firefox:
The page isn't redirecting properly, Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies.
RewriteCond %HTTP_HOST !^www. [NC]
RewriteRule ^(.*)$ http://www.%HTTP_HOST/$1 [R=301,L]
If you are redirecting from one completely different domain to another then you would not expect to be able to use %HTTP_HOST in the target. For example, the above would result in example.rhcloud.com being redirected to www.example.rhcloud.com - which is not the desired result. Then the following redirect to your actual domain would never match.
All you need is something like the following before the "WordPress" directives. Note that the order of directives in .htaccess is important.
RewriteEngine On
RewriteCond %HTTP_HOST !=www.example.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=302,L]
This simply redirects to your desired domain if you are not already at your desired domain. There is no need for an explicit canonical www redirect, or checking for HTTPS (your new domain is not accessible by HTTPS).
Clear your browser cache before testing (301 redirects are cached). Change the 302 in the above to 301 when you are sure it's working OK.
So, in summary, your complete .htaccess file should look like:
RewriteEngine On
RewriteBase /
RewriteCond %HTTP_HOST !=www.example.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
# WordPress Defaults
RewriteRule ^index.php$ - [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]

Comments
Post a Comment