Apache Server configuration support - Getting an Internal Server Error with 301 Redirect

This is Interesting: Free IT Magazines  
Home > Archive > Apache Server configuration support > July 2006 > Getting an Internal Server Error with 301 Redirect





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Getting an Internal Server Error with 301 Redirect
info@fashion-electronics.co.uk

2006-07-29, 1:22 pm

Guys,

I'm trying to do 301 redirect, but I'm struggling. The redirect rule I
have is this :

redirect 301 "/somepage.php?page=MP3 Players" /new_page

( Note the space in the first path, and the lack of extention in the
second. )

I have a mod-rewrite rule that deals with the second bit :

RewriteRule ^new_page$ somepage.php?page=MP3\ Players and this works
fine.

What am I doing wrong in the 301 redirect ???

Cheers,
Maxx

HansH

2006-07-29, 7:20 pm

<info@fashion-electronics.co.uk> schreef in bericht
news:1154191876.023061.40010@i42g2000cwa.googlegroups.com...
> I'm trying to do 301 redirect, but I'm struggling. The redirect rule I
> have is this :
> redirect 301 "/somepage.php?page=MP3 Players" /new_page
>
> ( Note the space in the first path, and the lack of extention in the
> second. )
>
> I have a mod-rewrite rule that deals with the second bit :
>
> RewriteRule ^new_page$ somepage.php?page=MP3\ Players and this works
> fine.
> What am I doing wrong in the 301 redirect ???

The error logged in your error_log might be more informative, please quote.

On second thought IF both would work, I think they'ld cause a redirect loop
....

It seems the space in your query string was the initial bother.
Tell about it, might be php related

HansH


info@fashion-electronics.co.uk

2006-07-30, 7:32 am

I think you're right about the redirect loop. Not sure how I'm going to
get round that. I need to point google to the new mod-rewrite pages,
which actually point to the original pages.

ie I need google to index fashion-electronics/mp3_players even though
it still uses the listpage.php?page=MP3 Players

Any ideas ??
Mark


HansH wrote:
> <info@fashion-electronics.co.uk> schreef in bericht
> news:1154191876.023061.40010@i42g2000cwa.googlegroups.com...
> The error logged in your error_log might be more informative, please quote.
>
> On second thought IF both would work, I think they'ld cause a redirect loop
> ...
>
> It seems the space in your query string was the initial bother.
> Tell about it, might be php related
>
> HansH


HansH

2006-07-30, 1:23 pm

<info@fashion-electronics.co.uk> schreef in bericht
news:1154255122.178494.76820@b28g2000cwb.googlegroups.com...

Do change the emailadres your newsreader uses to
info@fashiondashelectronicsdotco.uk to avoid a flood of spam.

http://www.linkvendor.com/seo-tools...ns-from-ip.html
shows 216 more sites listed at the same IP as yours.
I take it you are not in control of the server and any tweaking is limited
to .htaccess. That is drasticly limitting the options available ...
[vbcol=seagreen]
quote.

Missed at first glance: URL must be escaped, thus _if_ query_string is
allowed here
redirect 301 /listpage.php?page=MP3+Players /mp3_players/
redirect 301 /listpage.php?page=MP3%20Players /mp3_players/
might do a better job for the two variants of escaping a space
However, you will loose other query string parts like start=10, see below.
[vbcol=seagreen]
loop[vbcol=seagreen]
> I think you're right about the redirect loop.

Oops, no loops yet: your RewriteRule is NOT doing _external_redirects_

> ie I need google to index fashion-electronics/mp3_players even though
> it still uses the listpage.php?page=MP3 Players

In your /.htaccess try -untested-:
RewriteEngine On

RewriteCond %{QUERY_STING} "\bpage=MP3 Players\b"
RewriteRule listpage.php
http://www.fashion-electronics.co.uk/mp3_players/ [R301,L]

RewriteRule mp3_players listpage.php?page=MP3+Players [NE,QSA,L]
(Note NE keeps some version of apache from escaping the ?. However, usage
implies manually escaping the space to +. QSA adds original querystring like
start=10 to the result.)

and repeat this another 7 times for other categories ...
.... whished RewriteMap to be accepted in .htaccess.
.... be aware using /.htaccess this way may have a strong performance
penalty!

Google shows the same result for your domain with and without www prefixed.
You may want to tackle that to avoid Google banning either or both for
duplicate content soner or later.
Try to rerail any lazy visitor by appending to /.htaccess
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.fashion-electronics.co.uk/$1 [R=301,QSA,L]

Don't forget to deregister your non-prefixed domain with Google.

HansH


info@fashion-electronics.co.uk

2006-07-30, 7:22 pm

Thanks Hans, ( I think !! )

I'm very new at this .htaccess stuff, so it may take me a while to sift
through and understand what you've written. You are right that I don't
have control of the server, and so things are restricted to .htaccess
bits.

My host helped out by re-writing the 301 rule to :

RewriteRule "^/listpage.php?page=MP3\ Players" /mp3_players [R=301]

But I don't think it works, as when you type in :

http://www.fashion-electronics.co.u...e=MP3%20Players it
still accesses that page with the address as shown. Though now
obviously you don't get an internal server error.

However, having had a look at google's cache of both versions of that
page now :

http://www.fashion-electronics.co.u...e=MP3%20Players
and
http://www.fashion-electronics.co.uk/mp3_players

it appears that google has very recently sorted the PR out, and that
the cache of the old version now points to the new url. I've had the
rewrite rule up for about 3 - 4 months.

I'm hoping that because google has updated this of it's own accord, it
won't now ban either of the URL's, and maybe eventually it will drop
the old one. But I'm reluctant to go ahead and release the new site
with the new URLs until I can be sure that that won't happen.

Mark.


HansH wrote:
> <info@fashion-electronics.co.uk> schreef in bericht
> news:1154255122.178494.76820@b28g2000cwb.googlegroups.com...
>
> Do change the emailadres your newsreader uses to
> info@fashiondashelectronicsdotco.uk to avoid a flood of spam.
>
> http://www.linkvendor.com/seo-tools...ns-from-ip.html
> shows 216 more sites listed at the same IP as yours.
> I take it you are not in control of the server and any tweaking is limited
> to .htaccess. That is drasticly limitting the options available ...
>
> quote.
>
> Missed at first glance: URL must be escaped, thus _if_ query_string is
> allowed here
> redirect 301 /listpage.php?page=MP3+Players /mp3_players/
> redirect 301 /listpage.php?page=MP3%20Players /mp3_players/
> might do a better job for the two variants of escaping a space
> However, you will loose other query string parts like start=10, see below.
>
> loop
> Oops, no loops yet: your RewriteRule is NOT doing _external_redirects_
>
> In your /.htaccess try -untested-:
> RewriteEngine On
>
> RewriteCond %{QUERY_STING} "\bpage=MP3 Players\b"
> RewriteRule listpage.php
> http://www.fashion-electronics.co.uk/mp3_players/ [R301,L]
>
> RewriteRule mp3_players listpage.php?page=MP3+Players [NE,QSA,L]
> (Note NE keeps some version of apache from escaping the ?. However, usage
> implies manually escaping the space to +. QSA adds original querystring like
> start=10 to the result.)
>
> and repeat this another 7 times for other categories ...
> ... whished RewriteMap to be accepted in .htaccess.
> ... be aware using /.htaccess this way may have a strong performance
> penalty!
>
> Google shows the same result for your domain with and without www prefixed.
> You may want to tackle that to avoid Google banning either or both for
> duplicate content soner or later.
> Try to rerail any lazy visitor by appending to /.htaccess
> RewriteCond %{HTTP_HOST} !^www
> RewriteRule (.*) http://www.fashion-electronics.co.uk/$1 [R=301,QSA,L]
>
> Don't forget to deregister your non-prefixed domain with Google.
>
> HansH


HansH

2006-07-30, 7:22 pm

<info@fashion-electronics.co.uk> schreef in bericht
news:1154287165.708083.246580@75g2000cwc.googlegroups.com...
usage[vbcol=seagreen]
like[vbcol=seagreen]
[vbcol=seagreen]
>
> I'm very new at this .htaccess stuff, so it may take me a while to sift
> through and understand what you've written. You are right that I don't
> have control of the server, and so things are restricted to .htaccess
> bits.

True, rewriterules and friends are a pit of snakes ...
.... just learn to play the flute the way they like ;-)
Regular expresions -aka the '\bpage=MP3 Players\b' stuff- are mindtwister
too, results may very per version of apache.

> My host helped out by re-writing the 301 rule to :
> RewriteRule "^/listpage.php?page=MP3\ Players" /mp3_players [R=301]

That's no help ... (excuse me for sounding both blunt and arogant)
A rewriterule is _only_ applied on the part of the URI _before_ the
questionmark, the part thereafter is the query_string. That's why I have
split the job to a rewriterule and rewritecond.

> But I don't think it works, as when you type in :
> http://www.fashion-electronics.co.u...e=MP3%20Players it
> still accesses that page with the address as shown. Though now
> obviously you don't get an internal server error.
>
> However, having had a look at google's cache of both versions of that
> page now :
> http://www.fashion-electronics.co.u...e=MP3%20Players
> and
> http://www.fashion-electronics.co.uk/mp3_players


And even www.fashion-electronics.co.uk/listp...age=mp3_players
to adept to this veriant the condition needs to be changed to
RewriteCond %{QUERY_STING} "\bpage=MP3[ _]Players\b"

> it appears that google has very recently sorted the PR out, and that
> the cache of the old version now points to the new url. I've had the
> rewrite rule up for about 3 - 4 months.

Google had made some great ... I mean huge ... changes in their algorithmes
in the last monthes.
This may have slowed down revisiting, they might have held back your
site -due to in their perspectives too many changes in too short a period-.
it might have been the rurn of the poolar winds as well, nobody can tell for
sure. :-|

> I'm hoping that because google has updated this of it's own accord, it
> won't now ban either of the URL's, and maybe eventually it will drop
> the old one.

They will eventually drop the old ones, sending 301 will speed thing up -and
keep visitors form hitting 404s-.
You may consider including the old script in your robots.txt to drop it even
before being revisited. However, this may cause neither the old nor the new
links to be visible in results for a while. That is nevertheless still
better -or less worse-, than being banned due to duplicate content for about
half a year

> But I'm reluctant to go ahead and release the new site
> with the new URLs until I can be sure that that won't happen.

There is hardly no way to predict the misterious ways of Google ...

About what apears to me as the new site ... in the lefthand menu [only] the
link to 'MP3 Players' addresses the updated script
/listpage1.php?page=MP3%20Players directly

Further, your XHTML has some flaws, use a validator to guide you.
https://addons.mozilla.org/firefox/249/ offers a nice OFFLINE validater to
FireFox. Also, positioning is sometimes compromised -on both IE 6.0 and FF
1.5.0.5 on WindowsXPsp2-, like when windowwidth is too small to contain an
object .

HansH


info@fashion-electronics.co.uk

2006-07-31, 7:33 am

Well Hans, you've certainly given me quite a lot to think about.

I'm going to have to go and do some more reading on rewrite rules and
conditions as I'm not convinced I understand the difference.

The "new" third version of the mp3_player page is incorrect ( as you
will see from the zero results it produces, and I'll have to have a
look at preventing that ).

The "new look" site mp3 link is actually still using the full length
URL at the moment as the mp3_players was a test, and the current site
is still using it at the moment. The idea is that I'm going to to
change the filenames from listpage1.php for the new site, to
listpage.php as per the current site, so that any of the old links are
still valid if I can't sort out the rewrites properly.

Hans, Am I right in thinking that a 301 will send the new page to the
requester, and the page then gets re-requested with the new URL ?? and
does a normal re-write just send people though to the end page WITHOUT
a re-request ??

I will validate the XHTML with a validator, and see what needs sorting.

Many many thanks for your help.

Mark.

HansH

2006-07-31, 7:33 am

<info@fashion-electronics.co.uk> schreef in bericht
news:1154327887.273429.298550@b28g2000cwb.googlegroups.com...
> I'm going to have to go and do some more reading on rewrite rules and
> conditions as I'm not convinced I understand the difference.

A request has to match the rule _and_ satisfy all of the conditions set
_before_ it.
http://httpd.apache.org/docs/2.0/mo...InternalRuleset

> Hans, Am I right in thinking that a 301 will send the new page to the
> requester, and the page then gets re-requested with the new URL ??

Yes, a rewriterule with flag [R=301] will not send the content of any file,
but rather the URL of an alternate location. The agent then may retrieve
content from that location in an additional request. More about HTTP request
and response headers at http://www.ietf.org/rfc/rfc2616.txt
Use http://livehttpheaders.mozdev.org/installation.html with FireFox to see
them live.

> and does a normal re-write just send people though to the end page
> WITHOUT a re-request ??

Right, although mod_rewrite is said 'to rewrite requested URLs on the fly',
most of the times it 'only' rewrites the URL's _mapping_ to a (local) file.
This mapping is internal to Apache, the agent gets -and does not need to
have one- no clue on the local path at all.

HansH




info@fashion-electronics.co.uk

2006-07-31, 1:27 pm

That's good,

So in theory the original premise that I was trying to achieve should
be ok, and shouldn't cause a loop of any sort.

ie mapping google / users from the original listpage.php to mp3_players
with a 301

and then actually using listpage.php from a "normal" mod-rewrite when
mp3_players is re-requested so to speak.

Mark.


HansH wrote:

> Yes, a rewriterule with flag [R=301] will not send the content of any file,
> but rather the URL of an alternate location. The agent then may retrieve
> content from that location in an additional request. More about HTTP request
> and response headers at http://www.ietf.org/rfc/rfc2616.txt
> Use http://livehttpheaders.mozdev.org/installation.html with FireFox to see
> them live.
>
> Right, although mod_rewrite is said 'to rewrite requested URLs on the fly',
> most of the times it 'only' rewrites the URL's _mapping_ to a (local) file.
> This mapping is internal to Apache, the agent gets -and does not need to
> have one- no clue on the local path at all.
>
> HansH


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com