saintwright
saintwright

Reputation: 11

301 redirect not working in Wordpress

I have some rewrite code in my .htaccess file. I have moved a static HTML site into wordpress and need the following to work:

  1. redirect http://domain.com.au/ to http://www.domain.com.au/
  2. redirect (the old static home page) index.html to http://www.domain.com.au/

I cannot get either to work, I have tried all the various methods that have been suggested. The domain.com.au to http://www.domain.com.au works for all pages except for the home page, e.g. http://domain.com.au/ourteam redirects to http://www.domain.com.au/ourteam

But it will not redirect for the root (home page).

Also I get a page not found error for the index.html redirect.

My .htaccess file is:

Options +FollowSymlinks
RewriteEngine on
### re-direct index.html to root
RewriteCond %{THE_REQUEST} ^.*\/index\.html
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
### non www to www
RewriteCond %{HTTP_HOST} ^domain\.com\.au$ [NC]
RewriteRule ^(.*)$ http://www.domain.com.au/$1 [R=301,L]

redirect 301 /team.html http://www.domain.com.au/our-team/
redirect 301 /contact.html http://www.domain.com.au/contact-us/

Anyone help - I am tearing my hair out with this!

Upvotes: 1

Views: 9889

Answers (3)

Stevan
Stevan

Reputation: 11

As you are using rewrite rules you need to set up the 301s in a rewrite format that's the only way it will work.

RewriteRule ^/team.html$ http://www.domain.com.au/our-team/ [R=301,L]

Upvotes: 0

Shef
Shef

Reputation: 45589

Try:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on

### non www to www
RewriteCond %{HTTP_HOST} ^domain.com.au [NC]
RewriteRule ^(.*)$ http://www.domain.com.au/$1 [R=301,L]

### re-direct index.html to root
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.domain.com.au/ [R=301,L]

redirect 301 /team.html http://www.domain.com.au/our-team/
redirect 301 /contact.html http://www.domain.com.au/contact-us/

# WrodPress rules begin here...
</IfModule>

Upvotes: 0

goahead_taccom
goahead_taccom

Reputation: 21

Sorry, i just had trouble with this and found: Using htaccess to 301 redirect, not working

Apparently you have to put the redirects above the #begin wordpress as apache processes the rewrites and never gets to your redirects.

Upvotes: 2

Related Questions