0

Currently I have the following in my .htaccess file for a forum site.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule ^/?$ http://example.com/forums/ [L,R=301]

It works perfect for redirecting everything like (http)://example.com, www.example.com, (http)://www.example.com etc. to example.com/forums which is what I wanted.

I now want to have everything redirect to (https)://example.com/forums but am running into problems with existing links such as example.com/forums/stuff.

I can only get example.com to redirect to https://example.com/forums, any direct links such as example.com/forums/stuff etc. will not redirect to the https version, any ideas?

Cyclonecode
  • 29,115
  • 11
  • 72
  • 93

1 Answers1

0

You need 2 redirect rules. One rule to redirect landing page to forums page and another rule to redirect http -> https:

RewriteEngine On

# redirect landing page to /forums/
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com [NC]
RewriteRule ^/?$ https://%{HTTP_HOST}/forums/ [L,R=301]

# redirect http -> https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • The first redirect rule works but for some reason the second rule does not work to forward existing links like example.com/forums to https://example.com/forums – steveoverflow Dec 16 '16 at 18:57
  • If you have `/forums/.htaccess` then place 2nd rule in that .htaccess – anubhava Dec 16 '16 at 19:15