.htaccess in wordpress is not implementing the redirect from www to non-www

am working on wordpress. And i want to apply a redirect from www to non-www. There is many solutions online, but non of them worked for me, maybe because htaccess in wordpress works differently?

# BEGIN WordPress
# Директивы (строки) между `BEGIN WordPress` и `END WordPress`
# созданы автоматически и подлежат изменению только через фильтры WordPress.
# Сделанные вручную изменения между этими маркерами будут перезаписаны.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteCond %{HTTP_HOST} ^www\.eepir\.oxem\.ru [NC]
RewriteRule ^(.*)$ http://eepir.oxem.ru/$1 [L,R=302]



</IfModule>

# END WordPress

This is my code, i actually tried to post the rule outside of # BEGIN WORDPRESS but no result

Thank you.

Upvotes: 1

Views: 160

Answers (1)

MrWhite
MrWhite

Reputation: 45829

RewriteCond %{HTTP_HOST} ^www\.eepir\.oxem\.ru [NC]
RewriteRule ^(.*)$ http://eepir.oxem.ru/$1 [L,R=302]

You've put these "redirect" directives in the wrong place. They need to go at the top of the file, before the # BEGIN WordPress section.

By placing them after the WordPress front-controller then they are never going to be processed for anything other than existing static assets because the request has already been routed to /index.php. At which point processing is stopped.

You should never manually edit the code between the # BEGIN WordPress and # END WordPress comment markers since this code block is maintained by WordPress itself and your changes will likely get overwritten.

... but I covered all this in your question from yesterday?
htaccess redirect 301 is working but RewriteRule is not

You also need to configure WordPress itself to use the non-www hostname. ie. WP_HOME and WP_SITEURL - which should both be set in the dashboard.

maybe because htaccess in wordpress works differently

.htaccess works the same with WordPress as anything else. .htaccess doesn't really have much to do with WordPress itself.


UPDATE: It seems www.eepir.oxem.ru has no DNS configured so the request does not even reach your server (for the redirect to occur). You need to configure the appropriate A record for www.eepir.oxem.ru in the DNS, as you have done for eepir.oxem.ru and configure your server to accept requests to www.eepir.oxem.ru (if not already). Then your redirect should work.

Upvotes: 2

Related Questions