Mobile app version of vmapp.org
Login or Join
Correia994

: Redirecting openshift rhcloud domain to custom domain for SEO purposes Openshift application url: example.rhcloud.com Custom domain: example.com I came across this link and added the redirection rule.

@Correia994

Posted in: #Htaccess #ModRewrite #Redirects

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 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 .* %{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_HOST}%{REQUEST_URI} [R=301,L]

# Redirect non-www to www
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ www.%{HTTP_HOST}/ [R=301,L]


# Redirect openshift rhcloud domain to custom domain
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.rhcloud.com$
RewriteRule (.*)$ www.example.com/ [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 chrome:


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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Correia994

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ www.%{HTTP_HOST}/ [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 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 (.*) www.example.com/ [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 (.*) www.example.com/ [R=301,L]

# WordPress Defaults
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme