RewriteRule: content ok but 404 returned in HTTP :

RewriteRule: content ok but 404 returned in HTTP :

Posted by: DejanVesic
Posted on: 2006-03-08 12:55:00

Hello.

I have very strange problem; I changed structure of my site and used WordPress now to serve all pages on site.

One of the pages was:
http://www.vesic.org/english/

Now, that content is served now by calling:

http://www.vesic.org/index.php?p=21

I wanted to preserve nice URL's, so I created following section in .htaccess file:

#BEGIN /english section
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^english$ /english/ [R=301]
RewriteRule ^english/index.php$ /english/ [R=301]
RewriteRule ^english/index.html$ /english/ [R=301]
RewriteRule ^english/$ /index.php?p=21 [L]

</IfModule>
#END /english section


Now, behaviour is very strange:

- if you open http://www.vesic.org/english/ in browser you WILL get content BUT you will also get HTTP/1.x 404 code in header :-( (you need some tool which reports HTTP header info) which means "Page not found".

Can I somehow force Apache not to emit 404 code, i.e. to check FIRST if there is RewriteRule for given URL and ONLY if there is no such rule to emit 404?

Regards,
Dejan

Re: RewriteRule: content ok but 404 returned in HTTP :

Posted by: artgeek
Posted on: 2006-03-08 13:01:00

hmm, I did not get the 404 header for either link. When I purposely typed in a missing page I got your custom 404 in your wordpress template, so everything seems to work.

Wordpress will actually create a valid htaccess rewrite rule for you, you can specify exactly how you want your pages to appear. It automatically updates (must be chmodded 777) the htaccess page as your change it.

Re: RewriteRule: content ok but 404 returned in HTTP :

Posted by: DejanVesic
Posted on: 2006-03-08 13:05:00

In reply to:


hmm, I did not get the 404 header for either link.


Try to use any tool which obeys HTTP header codes (for example wget) or to use LiveHeaders for FireFox - you will get 404 not found and wget won't even retrieve page; ordinary browser will display page, but 404 will be in HTTP header.

Here are details:

G:Workwww.vesic.org>wget http://www.vesic.org/english/
--22:11:17-- http://www.vesic.org/english/
=> `index.html'
Resolving www.vesic.org... 208.97.139.196
Connecting to www.vesic.org|208.97.139.196|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
22:11:18 ERROR 404: Not Found.



Regards,
Dejan


Edited by DejanVesic on 03/08/06 01:11 PM (server time).

Re: RewriteRule: content ok but 404 returned in HTTP :

Posted by: artgeek
Posted on: 2006-03-08 13:15:00

hmm, ok

In reply to:

Response Headers - http://www.vesic.org/english/

Date: Wed, 08 Mar 2006 21:12:08 GMT
Server: Apache/1.3.33 (Unix) DAV/1.0.3 mod_fastcgi/2.4.2 mod_gzip/1.3.26.1a PHP/4.4.2 mod_ssl/2.8.22 OpenSSL/0.9.7e
X-Pingback: http://www.vesic.org/xmlrpc.php
X-Powered-By: PHP/4.4.2
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html

404 Not Found


wow, that IS weird.

I'm no rewrite expert. I use the built-in wordpress rewrite and it doesn't throw this error (just checked).

Re: RewriteRule: content ok but 404 returned in HTTP :

Posted by: DejanVesic
Posted on: 2006-03-08 13:32:00

In reply to:


wow, that IS weird.

I'm no rewrite expert. I use the built-in wordpress rewrite and it doesn't throw this error (just checked).



Well it IS weird :)

I have multiple WordPress installations on site, and only this one, which hosts root files/pages experience this problem; other URL's do just fine (no 404's).


Re: RewriteRule: content ok but 404 returned in HT

Posted by: kchrist
Posted on: 2006-03-08 14:01:00

The original URL returns a 301, but look where it's sending me:

$ lynx -head -dump http://www.vesic.org/english/
HTTP/1.1 301 Moved Permanently
Date: Wed, 08 Mar 2006 21:53:20 GMT
Server: Apache/1.3.33 (Unix) DAV/1.0.3 mod_fastcgi/2.4.2 mod_gzip/1.3.26.1a PHP
/4.4.2 mod_ssl/2.8.22 OpenSSL/0.9.7e
Location: http://www.vesic.org/english/?p=25
Connection: close
Content-Type: text/html; charset=iso-8859-1


The URL in the Location: header is where I'm being redirected to. Loading this URL results in the 404. Note the X-Pingback header, which tells us that WordPress is serving up this error:

$ lynx -head -dump http://www.vesic.org/english/?p=25
HTTP/1.1 404 Not Found
Date: Wed, 08 Mar 2006 21:55:00 GMT
Server: Apache/1.3.33 (Unix) DAV/1.0.3 mod_fastcgi/2.4.2 mod_gzip/1.3.26.1a PHP
/4.4.2 mod_ssl/2.8.22 OpenSSL/0.9.7e
X-Pingback: http://www.vesic.org/xmlrpc.php
X-Powered-By: PHP/4.4.2
Connection: close
Content-Type: text/html

Re: RewriteRule: content ok but 404 returned in HT

Posted by: DejanVesic
Posted on: 2006-03-08 14:05:00

In reply to:


he URL in the Location: header is where I'm being redirected to. Loading this URL results in the 404. Note the X-Pingback header, which tells us that WordPress is serving up this error:


$ lynx -head -dump http://www.vesic.org/english/?p=25

HTTP/1.1 404 Not Found


Sorry, I was just experimenting and you got in the middle of it :-( Try again please, I reverted old .htaccess now (you will get 404)

Regards,
Dejan

Tags: org indexstrange problemhtaccess filenicephpurlhttp