.htaccess redirect not working

I have added redirects to my .htaccess file.

Redirect 301 /portfolio_projlist.html http://www.jayrhindbuilders.com/selected-project-list/
Redirect 301 /portfolio_5res7.html http://www.jayrhindbuilders.com/portfolio/
#Redirect 301 /index.html http://www.jayrhindbuilders.com/
Redirect 301 /a http://www.jayrhindbuilders.com/
Redirect 301 /portfolio.html http://www.jayrhindbuilders.com/portfolio/
Redirect 301 /contact.html http://www.jayrhindbuilders.com/contact/

All of them are working except the one commented out, which brings up the error message:

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
What am I missing?

Is there another setting somewhere that automatically adds the /index.html to the URL when you request / ?
In that case it would constantly redirect from / to /index.html to / to /index.html to / etc etc …

That’s the only thing I can think of now; when I try your code on my host it works fine, redirects /index.html to / and then stops

Rémon,

Quite correct: DirectoryIndex is likely to be index.html ON THE SAME SERVER, i.e., LOOPY!

Regards,

DK

I checked http://www.jayrhindbuilders.com/index.html with the redirect commented out in the .htaccess file. I come up with a 404 page not found error.

Paul,

I clicked the link with index.html and it did give a 404. I then altered the index.html (with 404 contents, i.e., your 404 redirection was both not using ErrorDocument and not 301’d) to index.php and got the blank URI (redirection) with the home page.

Since there is no reason for anyone to link to index.html if it’s not there, (1) use DirectoryIndex index.php and (2) use ErrorDocument 404 / or add an R=301 flag to your redirection for 404’s (better yet, do both!).

Regards,

DK

The reason I need the redirect for .html is that Google still shows links to that URL after relaunching the site about a year ago. DK, I do not fully understand your suggestion. Can you show me code?

Paul,

I’m not sure what you’re using to remove index.php (Berkshire home builders | Jay Rhind Builders | Stockbridge MA resolved to [url=http://www.jayrhindbuilders.com/]Berkshire home builders | Jay Rhind Builders | Stockbridge MA hiding the default script) from the URI so there are other things going on which you’ve not shown.

As for your code, I’m not sure what mod_alias’s handling of internal absolute links does, however, had I written your Redirects, I would have known that they were in the .htaccess of the DocumentRoot and eliminated the leading /'s you’d used (the /a may be problematic, too!).

As for index.html being served a 404 script is another oddity which is not displayed with your first post. The ErrorDocument statement’s syntax is

ErrorDocument {status is optional} {file/directory to redirect} {ABSOLUTE redirection}

where, for the 404 case I’d encountered, {status is optional} = 404, {file} was index.html (not /index.html) and the {ABSOLUTE redirection} could be either internal (/index.php or just plain / to let DirectoryIndex look for the default scripts in order) or the full URL which you’ve used.

Since your question was “What am I missing?”, I believe that, lacking other details, it would be that you do not need (and, apparently, Apache doesn’t like) leading /'s in the file/directory part of the statement.

Regards,

DK

Re

lacking other details, it would be that you do not need (and, apparently, Apache doesn’t like) leading /'s in the file/directory part of the statement.

I tried removing the leading / from

Redirect 301 /index.html http://www.jayrhindbuilders.com/

and still get the same 404 error message.

Paul,

What about

Redirect 301 index.html /index.php

OR

DirectoryIndex index.php

Redirect 301 index.html http://www.jayrhindbuilders.com/

Regards,

DK

None of these worked.

Paul,

Bummer! Since there is no reason for it not to work (with what you’ve shown above), either show your entire .htaccess OR use mod_rewrite for that one:

# after all your Redirect statements AND
# assuming Apache 2.x

RewriteEngine on
RewriteRule ^index\\.html http://www.jayrhindbuilders.com/ [R=301,L]
# if Apache 1.x, insert a / between ^ and index

BECAUSE there is no reason for Redirect not to do this successfully, I’d recommend showing your .htaccess as there is something going on there which is preventing the intended Redirection.

Regards

DK

Here is the complete .htaccess code:

# 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

#to redirect urls from old to new urls
Redirect 301 /portfolio_res2.html http://www.jayrhindbuilders.com/portfolio/
Redirect 301 /portfolio_5res4.html http://www.jayrhindbuilders.com/portfolio/
Redirect 301 /portfolio_5res1.html http://www.jayrhindbuilders.com/portfolio/
Redirect 301 /portfolio_5res6.html http://www.jayrhindbuilders.com/portfolio/
Redirect 301 /portfolio_5res2.html http://www.jayrhindbuilders.com/portfolio/
Redirect 301 /portfolio_res1.html http://www.jayrhindbuilders.com/portfolio/
Redirect 301 /portfolio_res6.html http://www.jayrhindbuilders.com/portfolio/
Redirect 301 /portfolio_projlist.html http://www.jayrhindbuilders.com/selected-project-list/
Redirect 301 /portfolio_5res7.html http://www.jayrhindbuilders.com/portfolio/
#Redirect 301 /index.html http://www.jayrhindbuilders.com/
Redirect 301 /a http://www.jayrhindbuilders.com/
Redirect 301 /portfolio.html http://www.jayrhindbuilders.com/portfolio/
Redirect 301 /contact.html http://www.jayrhindbuilders.com/contact/

Paul,

A couple of comments, if I may, before telling you what’s causing your problem:

  1. Using <IfModule> tests on every request is an abuse of the server. If you were on my server, I’d cancel your account. I have a standard rant for that but you’ve had enough problems that it might be overboard.

  2. RewriteBase is a horrible bit of code designed to UNDO a mod_alias redirection so it should be removed.

BOTH of those are in the WP-generated code but, take my word for it, they do that for newbies who don’t have a clue. You are not in that class so get rid of them.

The problem is that you’ve allowed the WP code to redirect to index.php before your redirections. Uh, oh! On second thought, (1) mod_alias is a core module so it takes precedence over mod_rewrite and (2) your other Redirect code is working.

Other thoughts:

A. Your server may have Options MultiViews set and that could, as always, cause problems (here, redirecting to the other index.whatever file).

B. Your WP code is serving to redirect 404s to index.php and provide WP’s 404 response (which, if memory serves, is what I received when I tested your link). It’s my guess that this is what’s happening.

Regards,

DK

Thanks DK. So what do you suggest I replace for the WP code?

Paul,

I would:

  1. Move the WP code below the Redirects

  2. Uncomment the index.html Redirect

  3. Add (at the top) DirectoryIndex index.php (which will redirect / to index.php internally).

# My general layout
# Core directives, i.e., Options, DirectoryIndex, ErrorDocument (WP takes care of this)

# Core redirections (i.e., your Redirect statements)

# mod_rewrite statements
# WP mod_rewrite should be "corrected" by removal of
# -  <IfModule> wrapper
# -  RewriteBase directive

… for the reasons in the thread post above.

Regards,

DK