The root of my domain successfully redirects to a subdirectory, meaning example
redirects to example/abc
.
example
has no WordPress install.
example/abc
has its own WordPress install.
The homepage on is not HTTPS and I don't want it to be, however, I do want all the sub-pages to be HTTPS (eg.
or
)
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.
The root of my domain successfully redirects to a subdirectory, meaning example
redirects to example/abc
.
example
has no WordPress install.
example/abc
has its own WordPress install.
The homepage on http://example/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/abc/xyz
or https://example/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 Answer
Reset to default 1Presumably 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%{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.
example
redirects toexample/abc
" - where are you performing this redirect? "The homepage onhttp://example/abc
" - presumably you meanhttp://example/abc/
(with a trailing slash)? – MrWhite Commented Oct 21, 2018 at 9:53