Forum Moderators: phranque

Message Too Old, No Replies

Unresponsive 301 Redirects (or perhaps .htaccess)

Redirects aren't functioning, mod rewrite available.

         

Roswellb

1:09 am on Oct 16, 2011 (gmt 0)

10+ Year Member



The company name has changed, we're swapping domains and I'm setting up redirects. Here's where I'm experiencing some unwanted issues.

Options +FollowSymLinks

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^olddomain.nl [NC]
RewriteRule ^(.*)$ http://www.olddomain.nl/$1 [L,R=301]

Redirect 301 / http://www.newdomain.nl/
Redirect 301 /info/ http://www.newdomain.nl/informatie/
Redirect 301 /reserveren/ http://www.newdomain.nl/informatie/verhuur


That's a copy of my .htaccess, I checked with phpinfo and mod_rewrite is available and the server's running Apache/2.2.3 (CentOS).

At this point I'm not certain whether the .htaccess is being ignored or what might be the cause of the situation, it's certainly frustrating.

I'm at loss now with what I should do, I've added redirects dozens of times in the past and I've never run into this.
Is anyone able to shed some light on this, unique to me, situation?

lucy24

1:29 am on Oct 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



:: peering into crystal ball ::

g1 is going to tell you that
#1 the add-www redirect should come after everything else, because you're only picking up the redirects that haven't been covered by any other rule,
and
#2 combining mod_alias (Redirect by that name) and mod_rewrite (RewriteRule, optionally ending in [R=301]) in the same htaccess is taking your life into your hands.

In this case you've made a potentially fatal error: forms like /info/ do not have the same meaning in mod_alias that they do in mod_rewrite.

mod_rewrite: [httpd.apache.org...]
mod_alias: [httpd.apache.org...]

g1smd

1:30 am on Oct 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Look closely at what you have coded.

Make a list of what on the old domain needs to be redirected directly to the new domain (hint: non-www and www both need to be redirected directly to the new domain).

See that your code doesn't do that.

Don't mix RewriteRule and Redirect in the same site. Use RewriteRule for all of your rules.

Put the redirects (using a RewriteRule each) for specific pages ahead of your catch-all non-www and www redirect code.

Don't put the (.*) rule first otherwise none of the other rules get to run.

Your new code will have three RewriteRules, in this order. One for ^info/, one for ^reserveren/ and the last for (.*) requests.

I assume this code is going on the old domain.

Is the new site hosted on the same server? If it eventually is, there are yet more simplifications that can be done if both the old and new domain could be pointed at the same server.

Roswellb

10:43 am on Oct 16, 2011 (gmt 0)

10+ Year Member



First of all, thank you both for your replies. WIth this new information in mind I've altered the .htaccess again with no prevail. The two domains are hosted on seperate servers. But I have some additional information I feel stupid about having left out.

This is the current .htaccess I've added some # so you can check if my understanding of its functioning is correct;

#Activate mod_rewrite module
Options +FollowSymLinks
RewriteEngine On

#Prevent faulty regular expression from creating infinite loops
RewriteOptions MaxRedirects=10

#Set rewrites to incorporate URLbase
#RewriteBase /

RewriteRule ^info$ http://www.p79.nl/informeren/ [R=301,NC]
RewriteRule ^reserveren$ http://www.p79.nl/verhuur/ [R=301,NC,L]


The redirects are once again not working but at the same time, there is no physical location on the old domain called info. It was a path created by the previous CMS using .htaccess. Obviously there are still people linking to it which is why I want to redirect those towards the new domain.

The rewrite rules for 'info' and 'reserveren' are turning up 404 not founds rather than redirecting. So at this point I am still questioning if my .htaccess is even being read, so I tested it with just a non-www to www rewrite which resulted in this .htaccess;

#Activate mod_rewrite module
Options +FollowSymLinks
RewriteEngine On

#Prevent faulty regular expression from creating infinite loops
RewriteOptions MaxRedirects=10

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


This also did nothing.

Once again thank you for your advice and help so far.

g1smd

7:35 pm on Oct 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



there is no physical location on the old domain called info

There doesn't need to be. The code
RewriteRule ^info$

simply listens for a GET request that asks for the /info path as a URL.

Every rule needs the [L] flag. It is missing from at least one.

Roswellb

8:03 pm on Oct 16, 2011 (gmt 0)

10+ Year Member



Then I am at loss why they're turning up 404 results.

g1smd

8:34 pm on Oct 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What does Live HTTP Headers have to say about the matter?

Look very carefully at the results.

Roswellb

8:57 pm on Oct 16, 2011 (gmt 0)

10+ Year Member



The results show nothing out of the ordinary to me but I am perhaps not looking at the right part. I can say for a fact that the rewrite rules are not being read on the server in question as it worked perfectly fine on my own server hosted elsewhere.

Yet the mod_rewrite is on so I am uncertain as to why It would not work.

lucy24

10:20 pm on Oct 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There doesn't need to be. The code
RewriteRule ^info$
simply listens for a GET request that asks for the /info path as a URL.

With the final $ isn't it constrained to requests for the exact string "info" ? Don't know about roswellb, but on my (shared) server this would always fail, because the trailing-slash redirect and the directory indexing both happen before the request reaches my own htaccess.

RewriteOptions MaxRedirects=10

By weird coincidence I have only just looked this up after seeing it in a different thread. Unless your server is running something in the range 2.0.45 through 2.0.x-- which I devoutly hope it isn't-- this RewriteOption will not be recognized. But that is OK, because there's a core default that does much the same thing.

If your Rule says ^info without the ending anchor, it ought to work.