Why is my .htaccess file not redirecting - wordpress

I am trying to redirect using a .htaccess file and it's not working. The syntax seems to be correct. Does any one have any ideas what is incorrect?
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Redirect 301 /www.easycovertarp.com/ http://www.aeroindustries.com/products/easy-cover/

Insert this rule just below RewriteBase line:
RewriteCond %{HTTP_HOST} =local.aero.com
RewriteRule ^/?$ http://www.aeroindustries.com/products/easy-cover/ [L,R=301]
Ordering is important in mod_rewrite rules so this rule must be placed above shown WP rules.

Related

wordpress http to https redirect loop

I am trying to force my site to load in HTTPS. I can create a redirect in PHP which works for PHP files, but I want all requests forced to HTTPS - JS, CSS, Images, etc.
Here's what I have in my .htaccess:
ErrorDocument 401 default
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
I have tried various methods of this by placing the redirect in different locations and such, but everything seems to make this into a redirect loop. Any ideas what I could do to fix that?
Thank you.
Keep your http to https rules before internal WP rule:
ErrorDocument 401 default
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=302]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Make sure WP's home URL and site URL also have https in permalink settings.
Set a 301 permanent redirect which is more SEO friendly. Already tested:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect all traffic to https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# Wordpress rules
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

301 Redirect Error in .htaccess, shows "Bots Get Naked Version" instead of redirecting

I am looking to write 301 redirects for a site. I would like the redirect to go from http://www.ehlconsulting.com/our-services-basic-services/ to http://www.ehlconsulitng.com/services/.
My .htaccess file is as follow
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ehlconsulting.com
RewriteRule (.*) http://www.ehlconsulting.com/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Redirect 301 /our-services-basic-services/ http://www.ehlconsulting.com/services/
When you go to the old URL it doens't redirect. Instead it shows "Bots get the naked version"
You probably don't want to use Redirect and want to move the actual redirect above your wordpress rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ehlconsulting.com
RewriteRule (.*) http://www.ehlconsulting.com/$1 [R=301,L]
RewriteRule ^our-services-basic-services/(.*)$ http://www.ehlconsulting.com/services/$1 [L,R=301]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The "Bots get the naked version" thing doesn't have to do with your rules, it's probably WPEngine or something that's doing that by default, and you might be able to override that by using a ErrorDocument 404 in your htaccess file. The problem with using a Redirect along with wordpress' RewriteRule's is that they conflict with each other.

WordPress 301 Redirect Spaces to Hypens

I have the following in my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /entertainment/
RewriteCond %{THE_REQUEST} (\s|%20)
RewriteRule ^([^\s%20]+)(?:\s|%20)+([^\s%20]+)((?:\s|%20)+.*)$ $1-$2$3 [N,DPI]
RewriteRule ^([^\s%20]+)(?:\s|%20)+(.*)$ /$1-$2 [L,R=301,DPI]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /entertainment/index.php [L]
</IfModule>
# END WordPress
The problem is that domain.com/entertainment/testing 1/ redirects to domain.com/testing-1 instead of domain.com/entertainment/testing-1/. How do I fix this?
The [DPI] flag used means discard path info. Hence, the rewrite base isn't taking effect. Either use
RewriteRule ^([^\s%20]+)(?:\s|%20)+(.*)$ /$1-$2 [L,R=301]
Or, append the directory name to the rewrite rule as
RewriteRule ^([^\s%20]+)(?:\s|%20)+(.*)$ /entertainment/$1-$2 [L,R=301,DPI]

Redirect all pages to new domain

I want to redirect all the pages of my website to a new domain with a redirect. I've managed to get it working on domain level but not on the subpages.
So olddomain.com redirects to newdomain.com but olddomain.com/contact doesn't redirect to newdomain.com. It still shows the old domain.
I've used multiple rewrites rules but none of them seem to works. Any help is much appreciated.
This is the code that I'm using right now in my .htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^racentegenkanker\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.racentegenkanker\.com$
RewriteRule ^(.*)$ "http\:\/\/againstcancer\.nl\/$1" [R=301,L]
For a full website redirection, you can use this (entire) .htaccess :
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://againstcancer.nl/$1 [R=301,L]
EDIT
For two domains running side by side, with one redirecting the other :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} racentegenkanker\.com$
RewriteRule ^(.*)$ http://againstcancer.nl/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

.htaccess rewrite rule not working for different pages

I had the page name as the-book.html, but now i changed the page name to about-the-book. I have used the rewrite rule as
`Redirect 301 /the-book.html http://www.xxx.com/about-the-book.html`
but it is not working.
my full .htaccess code is here
RewriteRule ^/the-book.html$ http://www.xxx.com/about-the-book.html [R=301]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteRule ^the-book.html$ http://www.example.com/about-the-book.html [R=301]
Not sure about the Redirect directive, but
RewriteRule ^the-book.html$ http://www.xxx.com/about-the-book.html [R=301]
should work nicely.
Edit:
Removed the leading / in the match part.

Resources