最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

redirect - SSL and www to non-www redirection works only on homepage - Wordpress

programmeradmin2浏览0评论

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\ [NC]
RewriteRule (.*) /$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). What I am doing wrong?

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\ [NC]
RewriteRule (.*) https://example/$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). What I am doing wrong?

Share Improve this question edited Feb 22, 2021 at 16:13 kacperrro99 asked Feb 22, 2021 at 14:53 kacperrro99kacperrro99 255 bronze badges 2
  • Shouldn't your redirect directives be at the top of the file? Why is the WP section repeated twice? – Tom J Nowell Commented Feb 22, 2021 at 14:58
  • @TomJNowell They should - I just changed it - thank you! As for the repeated WP section, I have no idea how that happened. Just fixed it – kacperrro99 Commented Feb 22, 2021 at 15:40
Add a comment  | 

1 Answer 1

Reset to default 0

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.

发布评论

评论列表(0)

  1. 暂无评论