Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite and mod_ssl not working together

404 error on using mod_rewrite on SSL pages

         

win_dir

11:02 am on Aug 21, 2004 (gmt 0)

10+ Year Member



Hi,

I've just started using mod_rewrite and it has been absolutely fine, until i tried accessing the following SSL url: [mysite.com...]

Apache ReWriteRule in apache2.conf:

ReWriteRule /Content/([A-Za-z0-9]+) /mysite.com/www/index.php?mode=contentpage&PageID=$1

P.S. this exact same rule works absolutely fine when i do [mysite.com...]

jdMorgan

2:09 pm on Aug 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



win_dir,

Welcome to WebmasterWorld!

We've had a spate of "weird" problems discussed recently, where it was reported that "mod_rewrite doesn't work with <insert other module name here>". In most cases, this had to do with the module load order in httpd.conf.

Apache modules are processed in reverse order from that indicated by the LoadModule directives -- Those listed first in the httpd.conf LoadModule list are processed last. So if mod_rewrite appears in the load list *before* another module, say mod_SSL or mod_php, then it won't be processed until *after* that module runs (if ever).

Since this is 'an easy fix' you might want to check this first.

Jim

win_dir

2:30 pm on Aug 21, 2004 (gmt 0)

10+ Year Member



Unfortunately that didn't work, have just tried mod_ssl both above and below mod_rewrite and no effect whatsoever. Have also just tried loading the conf file for mod_ssl the other way round too, still no effect.

win_dir

2:43 pm on Aug 21, 2004 (gmt 0)

10+ Year Member



Hi,

An update, just checked the headers and apprently its a 500 internal error rather than the 404 IE reports, darn IE

jdMorgan

3:06 pm on Aug 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check your server error log file. Sometimes it contains very useful information.

In order to override IE's annoying habit of providing "Friendly" error pages, simply make your custom error documents longer than 512 bytes. This overrides IE's annoying replacement of error documents.

Jim

win_dir

4:08 pm on Aug 21, 2004 (gmt 0)

10+ Year Member



I ought to do a custom 500 page but I haven't had the time yet, will soon though. Regarding the error log, first thing i checked, just the standard startup messages and a few errors from when i was experimenting with mod_rewrite on http.

I'd appreciate any other ideas because i can't really get on with a large part of my site that relies up on mod_rewrite working in SSL mode.

jdMorgan

4:37 pm on Aug 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, that's not very promising...

There are a couple of subtle problems with your RewriteRule, but they may not have anything to do with this problem. First, there are two common forms of RewriteRule, internal rewrites and external redirects. For internal rewrites, only a local URL-path should be specified, and for external redirects, a full canonical URL should be specified. In addition, your server performance will be improved by specifying start and end anchors for your pattern if possible, by using the [NC] (no-case) flag to make the pattern compare case-insensitive, and by using the [L] flag unless the output of the current rule, once invoked, needs to be further processed through the subsequent rules.

So, I'd suggest something like this:


RewriteRule ^/Content/([a-z0-9]+) /index.php?mode=contentpage&PageID=$1 [NC,L]

Also, many php users add a type declaration to their rule, which looks like this:

RewriteRule ^/Content/([a-z0-9]+) /index.php?mode=contentpage&PageID=$1 [NC,T=application/x-httpd-php,L]

These are just wild guesses; In order to proceed further, you'll need to find the source of the 500-Server Error. There are simply so many variables in server configuration that we'll need more information in order to make intelligent suggestions. You can also check the php error log, and try rewriting to a static html page just as an experiment to see if you still get a 500.

Jim

win_dir

6:00 pm on Aug 21, 2004 (gmt 0)

10+ Year Member



Nope, still absolutely nothing in the error log, still the 500 error, tried both of your suggested edits to the ReWrite code. Also tried doing a rewrite rule to a static html file, still the same problem, 500 error on https, fine on http. Hmm...this is mad, there isn't a log level above debug for apache is there?

win_dir

6:09 pm on Aug 21, 2004 (gmt 0)

10+ Year Member



Dude...i am one stupid *** ** * *****, i don't believe i wasted almost a whole day on a simple re-definition of the DocumentRoot in the default mod_ssl virtual host file. And why did i not have a look for a seperate SSL debug log. Thanks alot anyway, sorry for my stupidity.

jdMorgan

6:39 pm on Aug 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could help members with the same problem in the future by posting a description of precisely what was wrong, and I encourage you to do so.

Jim

win_dir

8:06 pm on Aug 21, 2004 (gmt 0)

10+ Year Member



Ah, yeah. sorry, got a little excited. Right, the problem was that on Gentoo Linux, perhaps other OS's too when installing mod_ssl it also puts a virtual hosts configuration file specially for https sites in the modules.d directory.

However i had left the default DocumentRoot directive in this file to /var/www/.... but my document root is elsewhere, so a quick change of path and all sorted.

I found this out from the mod_ssl logs i didn't know got created in the /var/log/apache2/ directory. Thanks for your time.

Kind Regards
Mark Rawson