Juan Gonzales
Juan Gonzales

Reputation: 1977

Redirect extension through htaccess

I want to redirect all "com" extensions to "org" extensions, even if they are https. This is what I have so far...

RewriteCond %{HTTP_HOST} domain.com$ [NC]
RewriteRule .* https://www.domain.org [R=301,L]

The problem is, this only redirects if it is "http". How can I also redirect if it is an https domain? Any help would be appreciated. Thank You Much.

Upvotes: 1

Views: 84

Answers (1)

Jon Lin
Jon Lin

Reputation: 143966

Try:

RewriteCond %{HTTP_HOST} domain.com$ [NC]
RewriteCond %{HTTPS}:s (on:(s)|off:s)
RewriteRule .* http%2://www.domain.org [R=301,L]

The second condition creates a capture group in the event that HTTPS is "on", otherwise, there is no capture group. The "s" is captured and then backreferenced using %2.

Additionally, you can redirect the URI as well by changing the rewrite rule line to:

RewriteRule ^(.*)$ http%2://www.domain.org/$1 [R=301,L]

Upvotes: 3

Related Questions