PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 27, 2022

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

 January 27, 2022     .htaccess, wordpress     No comments   

Issue

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.


Solution

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 static resources 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.


UDPATE: 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.



Answered By - MrWhite
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing