Forum Moderators: phranque

Message Too Old, No Replies

New with url rewrite

url rewrite redirection

         

papajay

11:44 am on May 10, 2009 (gmt 0)

10+ Year Member



Hello Apache masters,

Lately I work on my site with apache mod rewrite, a new site.
I've change my php script to output htm links.
Then I used mod rewrite with these htm links to execute with corresponding php query
example:
RewriteRule ^(.*)-page-([0-9]+)\.htm$ file.php?query=$1&start=$2 [L]

If I put the end with [R=301,L] it will redirect these htm link the the original php file, so I don't put anything except [L]

I got sitemap error message in google webmaster tool.
"we've test several url from sitemap, the url is redirecting, not a final destination."
Something close like that, I don't remember the exact one.
Maybe this is because of these htm links not end with [R=301,L].

Then I put this after several RewriteRule like above
RewriteRule ^/(.*)\.htm$ $1.php [R=301,L]
RewriteRule ^/(.*)\.php$ \/$1.htm [R=301,L]

I check the header status code, always return me with 200, no one with 302 or 301.
Do I've another solution to change the last two rewrite rule? so I can get the 301 status.
I got no error message in google, is this fixed yet?
Do I missed something here? Or I already on track?

Thanks in advance

g1smd

12:00 pm on May 10, 2009 (gmt 0)

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



If Google reports a redirect for a URL, then check using a Header Checker what status code is returned for your canonical URL.

If it is 301 or 302 then you DO have a redirect, and need to fix it so that it does not redirect.

If it is '200 OK' then the site is working right.

You need to check http and https requests for both www and non-www here.

Only one should return a 200 OK. The others should redirect or fail.

You need a more restrictive pattern than (.*) in your pattern. That matches the 'whole URL to the very end' and then has to backoff and retry many times to find a match.

You do need to add a redirect such that if someone requests a .php URL they are redirected to request the .html URL. That redirect should use a RewriteRule, with [R=301,L] flags, and should force the canonical domain at the same time. This new redirect should be listed before your existing rewrite.

See also: [webmasterworld.com...]

papajay

4:25 am on May 15, 2009 (gmt 0)

10+ Year Member



Thank you g1smd, sorry for late reply.
I had something to do in the real world :)
yes there is a regex pattern on it, just too lazy to write it.
All were return with 200, except moved pages that I intended to put 301 redirect.
I had none 302, I don't want to :)
but google seems know that the url was rewritten, even it return with 200.
It was shown on sitemap error, but its gone by now.