سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى wordpress.stackexchange
scroll top