Using .Htaccess do redirect on Openshift

Server Norckon 572℃ 0评论

1464153595-9120-htaccess-redirect-1

INTRODUCE

I built a website on Openshift, but sometimes I want to do a redirect on Openshift. Now the problem is how to do a redirect on Openshift. As usual, just write .htaccess rule and save to website root directory, redirect will take effect immediately. But on Openshift have some different, Openshift don’t allow global redirection.

INVALID RULE

Write the following rule into .htaccess will take a loop redirection.

RewriteEngine On
RewriteCond %{http_host} ^www.fcsys.org$ [NC]
RewriteRule ^(.*)$ http://fcsys.org/$1 [R=301,L]

VALID RULE

Searching on the Internet and get following rule, It work on Openshift.

Global Redirection

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(fcsys.org|fcsys.us)$ [NC]
RewriteRule ^(.*)$ http://fcsys.org/$1 [R=301,L]

Domain Redirection

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.fcsys.org$
RewriteRule ^webapp/wordpress/(.*)$ http://b.fcsys.org/$1 [R=301,L]

OTHER VALID RULE

There are some other redirection rules worked on Openshift.

1. Redirect domain.com to www.domain.com.

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

2. Redirect www.domain.com to domain.com.

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

3. Redirect olddomain.com to www.newdomain.com.

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

4. Redirect olddomain.com to newdomain.com.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !olddomain.com$ [NC]
EewriteRule ^(.*)$ http://newdomain.com$1 [L,R=301]

5. Redirect domain.com/file/file.php to otherdomain.com/otherfile/other.php.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^file/file.php$ http://www.otherdomain.com/otherfile/other.php [R=301,L]

6. Redirect domain.com to www.domain.com, and it doesn’t affect sub-domains.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www.a.com|www.b.com)$ [NC]
RewriteRule ^(.*)$ http://www.c.com$1 [L,R=301]

NOTE: The rule RewriteEngine On only need one time in same htaccess.

REFERENCE

AUTHOR

Pekaikon Norckon
2016-05-25 (WED)

喜欢 (0)
COMMENT
Cancel Comment
EMOJI

Hi, We need some information

  • Nickname (*)
  • E-Mail (*)
  • Website