Rewrite Rules Subvert Error Pages

#1
Hi,

I'm running Litespeed Web Server Standard v3.3.19 and Wordpress 2.6.2, and here are the rewrite rules I have in my Litespeed Virtual Host:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I took them from a previous installation on Apache, and they work, allowing Wordpress's pretty permalinks.

The problem is that absolutely everything is rewritten. Nothing ever goes to 404. Any string at all after the domain is rewritten as a directory, and then Wordpress serves up an empty page for it.

Any ideas? I'm looking at the rewrite logs and can't really make head or tail of it.

Thanks!
 
#3
Yes, under Apache any bad URL will cause these rules to serve the custom error page, 404.php which is handled by Wordpress.

Maybe that's the problem? A conflict between Wordpress and Litespeed over who serves the error?

I guess I need to figure out how to tell one of them to lay off.
 

mistwang

LiteSpeed Staff
#4
Yes, under Apache any bad URL will cause these rules to serve the custom error page, 404.php which is handled by Wordpress.
We tried it on a WP installation. it does display the 404 page. But the page does get rewritten to index.php first, then index.php calls wp-content/themes/default/404.php

So, I am not sure what exactly is the cause of the problem, maybe you can try disabling WP-Super Cache, once we identify what is the cause of the problem, we can investigate more. We set WP Super Cache to "Half on".
 
#5
I've discovered that the presence of either a percentage sign (%) or a back slash (\) will cause the 404 page to be served, which is interesting if not particularly illuminating to me. Here are some logs:

Code:
# A good URL:
[REWRITE] Rule: Match '/recent-work/' with pattern '.', result: 1
[REWRITE] stat( /opt/lsws/HAMBLOG/html/recent-work ) failed 
[REWRITE] stat( /opt/lsws/HAMBLOG/html/recent-work ) failed 
[REWRITE] Source URI: '/recent-work/' => Result URI: '/index.php'
[REWRITE] Last Rule, stop!

# A bad URL:
[REWRITE] Rule: Match '/recent-work/obviously-not-a-real-url' with pattern '.', result: 1
[REWRITE] stat( /opt/lsws/HAMBLOG/html/recent-work ) failed 
[REWRITE] stat( /opt/lsws/HAMBLOG/html/recent-work ) failed 
[REWRITE] Source URI: '/recent-work/obviously-not-a-real-url' => Result URI: '/index.php'
[REWRITE] Last Rule, stop!
[REWRITE] Rule: Match '/recent-work/obviously-not-a-real-url/' with pattern '.', result: 1
[REWRITE] stat( /opt/lsws/HAMBLOG/html/recent-work ) failed 
[REWRITE] stat( /opt/lsws/HAMBLOG/html/recent-work ) failed 
[REWRITE] Source URI: '/recent-work/obviously-not-a-real-url/' => Result URI: '/index.php'
[REWRITE] Last Rule, stop!
# Rewritten twice, coming back the second time with a trailing slash,
# transforming the bad URL into a directory that doesn't exist.

# A URL with a percentage sign on the end:
[REWRITE] Rule: Match '/recent-work/obviously-not-a-real-url' with pattern '.', result: 1
[REWRITE] stat( /opt/lsws/HAMBLOG/html/recent-work ) failed 
[REWRITE] stat( /opt/lsws/HAMBLOG/html/recent-work ) failed 
[REWRITE] Source URI: '/recent-work/obviously-not-a-real-url' => Result URI: '/index.php'
[REWRITE] Last Rule, stop!
# The percentage sign doesn't show up in the log, but the 404
# was served.

# A URL with a back slash:
[REWRITE] Rule: Match '/recent-work/obviously-not-a-real-url\' with pattern '.', result: 1
[REWRITE] stat( /opt/lsws/HAMBLOG/html/recent-work ) failed 
[REWRITE] stat( /opt/lsws/HAMBLOG/html/recent-work ) failed 
[REWRITE] Source URI: '/recent-work/obviously-not-a-real-url\' => Result URI: '/index.php'
[REWRITE] Last Rule, stop!
# The 404 was served.
I guess the thing I find most puzzling is that the logs read pretty much the same regardless of what actually happens: every URL reports "result:1" and "failed" and finally, "=> Result URI: '/index.php'" Is that normal?

Thanks for the help!
 
#7
Actually, I hadn't used WP-Super Cache until you mentioned it. So I installed it and played around with the settings (Fully on, half-on, Fully on but without Super Cache, and completely off and deactivated, but it didn't make any difference. Then just now I turned off all plugins and still no change. :(
 

mistwang

LiteSpeed Staff
#8
I think I probably know what is wrong, you configured the rewrite rule at vhost level, but those are designed to be in .htaccess or at directory/context level.

If you do not want to use .htaccess, you can create "/" context point to the document root of your web site, then add rewrite rule there.
 
#9
Yes! You are correct. Creating a root context and adding the rewrite rules there works perfectly. Thank you very much!

I never was able to get the .htaccess file to work, but no need to now.
 
Top