2

The root of my domain successfully redirects to a subdirectory, meaning example.com redirects to example.com/abc.

example.com has no WordPress install.

example.com/abc has its own WordPress install.

The homepage on http://example.com/abc is not HTTPS and I don't want it to be, however, I do want all the sub-pages to be HTTPS (eg. https://example.com/abc/xyz or https://example.com/abc/thistoo)

My current .htaccess file is the standard WordPress stuff...

# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /abc/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /abc/index.php [L]
</IfModule>

# END WordPress

I've checked and tried many other solutions that I've found here but so far no joy.

p.s. I know to re-save permalinks after making changes like this to the .htaccess file.

1
  • "example.com redirects to example.com/abc" - where are you performing this redirect? "The homepage on http://example.com/abc" - presumably you mean http://example.com/abc/ (with a trailing slash)?
    – MrWhite
    Commented Oct 21, 2018 at 9:53

1 Answer 1

1

Presumably your .htaccess file is located in the /abc subdirectory? In which case you can do something like the following to force HTTPS on all sub-pages, except the homepage:

This needs to go at the very top of your .htaccess file:

RewriteCond %{HTTPS} !on
RewriteRule !^(index\.php)?$ https://example.com%{REQUEST_URI} [R=302,L]

This assumes that the SSL cert is installed directly on your application server.

The negated RewriteRule pattern !^(index\.php)?$ only matches non-empty (or not index.php) URL-paths, so this excludes the homepage.

Change the 302 (temporary) to 301 (permanent) only when you are sure it's working OK, to avoid caching issues. Clear your browser cache before testing.


Aside:

RewriteBase /abc/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /abc/index.php [L]

Since you have set the RewriteBase directive, you can remove the directory-prefix from the RewriteRule substitution (this is what the RewriteBase directive does):

RewriteRule . index.php [L]

However, since your .htaccess file is in the /abc subdirectory, then you don't actually need the RewriteBase directive or the directory-prefix.

1
  • 1
    That has worked perfectly, MrWhite. Thank you so much.
    – au_Martin
    Commented Oct 22, 2018 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.