htaccess rewrite not working in WordPress. Any ideas?

May 23, 2017 508 views
Apache WordPress Arch Linux

RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-Proto} !https

RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.mrtownhome.net [NC]
RewriteRule ^(.*)$ http://mrtownhome.net/$1 [L,R=301]

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUESTFILENAME} !-f
RewriteCond %{REQUEST
FILENAME} !-d
RewriteRule . /index.php [L]

1 comment
2 Answers

Hi @frankbiganski

What is it that isn't working?

It seems like your domain is pointing to different locations.
www.mrtownhome.net to InMotion Hosting
mrtownhome.net to CloudWays on DigitalOcean

And you're running both Nginx and Apache - as far as I can tell, which adds extra configuration overhead, which might be more difficult to setup correctly.

  • That was the problem... thanks for pointing that out. Got both pointing to the same host/Cloudways and that fixed the problem. I'll clean up the code as well. Thanks again.

@frankbiganski

How it should be setup really depends on what you're trying to do :-).

In the example you've posted, RewriteEngine On exists three times. Keep it at the top of the file and remove the other two instances of that line.

That should leave us with:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.mrtownhome.net [NC]
RewriteRule ^(.*)$ http://mrtownhome.net/$1 [L,R=301]

RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUESTFILENAME} !-f
RewriteCond %{REQUESTFILENAME} !-d
RewriteRule . /index.php [L]

With that, is this particular instance behind a proxy? I'm asking due to the second line. If so, then you may very well need a bit of code in wp-config.php to handle this instead of .htaccess.

Have another answer? Share your knowledge.