I have a htaccess file in the root of my public files on my web server:
Header set Content-Security-Policy: upgrade-insecure-requests
DirectoryIndex index.html index.php parking-page.html
RewriteEngine on
# Force www
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Force SSL
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE]
Options -Indexes
ErrorDocument 404 https://%{HTTP_HOST}/index.php
# for JWT auth
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
# end for JWT auth
I installed a Wordpress blog on /blog , and Wordpress creates a .htaccess file in that folder:
# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
I notice that, when I visit http://example.com/blog , it redirects me to https://www.example.com/index.php , while it should go to https://www.example.com/blog . Other pages, for example http://example.com/contact-us, successfully redirects to https://www.example.com/contact-us
Update:
- https://example.com/blog works fine (redirects to https://www.example.com/blog).
- http://www.example.com/blog is broken (redirects to https://www.example.com/index.php).