SSL and www to non-www redirection works only on homepage – WordPress

I’ve enabled SSL on my WordPress website and set redirection from www to non-WWW via the following code placed in .htaccess:

# REDIRECT WWW TO NON-WWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule (.*) https://example.com/$1 [L,R=301]
# REDIRECT HTTP TO HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

However, it works good only on homepage (example.com). What I am doing wrong?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You’ve put the directives in the wrong place, the canoncial redirects need to go before the # BEGIN WordPress section (the front-controller), otherwise, they are not going to be processed for anything other than physical files and directories. (The “homepage” maps to a physical directory, so is redirected).

For some reason you have also repeated the WordPress front-controller section, with a slight difference. You should only have one.

# BEGIN block author scans
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} (author=d+) [NC]
RewriteRule .* - [F]
# END block author scans

This section is also in the wrong place and needs to go before the # BEGIN WordPress section. You should remove the RewriteEngine and RewriteBase directives from this block.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x