Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Simple 301 redirect .htaccess isn't redirecting at all?

4:25 am on Jun 29, 2013 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 20, 2007
posts: 69
votes: 0

I've had my .htaccess file work perfectly for years on my GoDaddy Linux hosting. I've made no real changes, but just a few hours ago I discovered that all my redirects are creating 404 errors in all my browsers.

So I reduced my .htaccess file to it's most basic format and I can't even get this working:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ http://www.example.com/$1 [R=301,L]
Redirect 301 /about.html http://www.google.com

When I got to www.example.com/about.html, it will not redirect to www.google.com. Should it? Is there something wrong with my syntax? The first 2 rules work just fine, but the 301 redirect at the end doesn't do it's job.

I've tried so many different things, I'm at a loss. Any help would be appreciated!
8:04 am on June 29, 2013 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 20, 2007
posts: 69
votes: 0

Unbelievable. After 4~ hours on the phone we found the problem.

The geeks at GoDaddy messed up big time likely at the time when they migrated their servers to Apache 2.4 in the last month.

On their grid hosting plan you now have to specify the folder your website is located in, when you make a relative path. Unbelievable. One day you wake up and everything that all the websites that were working for 5 years are broken. No notification, no warning. Thousands of dollars down the drain.

So now

Redirect /path.html http://example.com/correctpath.html

has to be written like this:

Redirect /foldername/path.html http://example.com/correctpath.html

<sigh>Now that I changed all my redirects, I'll have to constantly test that they don't change it all back the way it was.</sigh>
8:10 am on June 29, 2013 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
votes: 244

Well, ###. Couldn't you have typed six minutes faster?

I'll let the following stand anyway.

:: bzzt! danger! bzzt! danger! ::

You've got mod_rewrite and mod_alias in the same htaccess. This can be perilous. Take any rules using mod_alias (Redirect by that name) and translate them to mod_rewrite form.

The bad news is that I don't see any way that this would affect your present situation.

Is the redirect to google just for experimental purposes so you can see things happening in the browser? You can achieve the same result by redirecting to a nonsense page like "foobar.html". Your screen will show your 404 page, but the browser's address bar will show example.com/foobar.html. Try it, anyway. It's remotely possible that some new server setting is interfering with off-site redirects. (It shouldn't, of course, but that's a separate problem once you've got it diagnosed.)

all my redirects are creating 404 errors in all my browsers

It would be a ### of a lot more worrying if there were errors in some browsers but not all of them. The only time you'll see browser-specific behavior is if you repeat a request that was previously redirected; then the browser may remember the redirect and won't try a fresh request.

When did the problem start? On shared hosting you may not have access to many days' worth of raw logs. (Mine defaults to 3; I changed it to 15 to give me more time to remember to get everything downloaded.)

The rules you've got are perfectly innocuous except for minor points like
(a) mixing mod_alias and mod_rewrite
(b) the three rules are in the precise opposite order to what they should be: you should go from individual page redirects, to redirects following a pattern, and then the "index.html" redirect and the domain-name canonicalization should be the very last two rules
(c) the form ^example.com is imperfect in several ways; it should ideally be
(d) the expression .* should never be used in mid-pattern if you can possibly help it. If you can't get by with a simple
%{THE_REQUEST} index\.html
then use

But all of this is minor spit-and-polish that should not prevent anything from working.

I've made no real changes, but

Mm, yes, it's the "but" that causes alarm.

Do you realize that you never explained the 404 errors? Was that purely a reference to requests for a nonexistent "about.html"?

Did mod_alias (Redirect by that name) work at some time in the past? It's not likely your host has changed Override settings. Those govern behaviors rather than specific modules and I don't think there's any way you could use mod_rewrite while not being able to use mod_alias. And if the server's mod_alias was broken, I think even GoDaddy would tell you.
9:03 am on June 29, 2013 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 20, 2007
posts: 69
votes: 0

Thank-you very much for your reply lucy. I entered my solution as soon as I discovered it. Now we're both sorry it wasn't sooner. :S

Yes, the redirect was just for experimental purposes. I could have made that clearer.

Yes, having mod_rewrite and mod_alias directives together can cause issues - none that I've experienced, but I've read they can get in each other's way.

Wow, you are sharp... I didn't realize that my my mention of 404 errors wasn't consistent with the example code that I provided, but you caught it. The 404 errors were because some of my redirects weren't actual files names. In the above code however, the redirect just wouldn't take place.

I am curious though about the minor points you brought up... like why the order of the rules should be reversed.
9:51 am on June 29, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
votes: 0

With the rules in your current order a request for example.com/index.html is first redirected to www.example.com/index.html and then to www.example.com/ in a two-step redirection chain.

You want to redirect in a single step. You do that by reversing the rule order and by ensuring the target of the index redirect specifies the full URL including protocol and hostname.

Change all Redirect and RedirectMatch directives to use RewriteRule.

Redirect 301 /about.html http://www.google.com

RewriteRule ^about\.html http://www.google.com/ [R=301,L]

with ^ on pattern start, escaping on literal period, trailing slash on target and [R=301] and [L] flags.

Order your rules from most specific to most general.

Escape literal periods in RegEx patterns.

Comment your code.

Leave a blank line after each RewriteRule.

^example.com [NC]


10:26 am on June 29, 2013 (gmt 0)



as they were off topic for this thread, 7 messages were spliced to an existing thread on this topic by phranque. Thread at: apache/4566749.htm [webmasterworld.com]
4:59 am on Jun 30, 2013 (utc -7)

[edited by: phranque at 12:07 pm (utc) on Jun 30, 2013]
[edit reason] clean up System tracks [/edit]