RewriteBase not working as expected as expected in

Topics: Developer Forum
Apr 30, 2010 at 3:30 PM
Edited Apr 30, 2010 at 3:44 PM

I have an application running in the root of my vhost, so the base is "/".  Using version I can do this:

RewriteBase ON
RewriteRule . index.php [L]

In anything I send in will output:


With it outputs:


which is then not found.  In other words, it does *not* seem to be adding the base.

To test, I'm literally just shutting down IIS, and renaming the dll so the intended version is iirf.dll .  Should I be swapping other files as well?

Also, I literally just rechecked the RewriteBase docs, and noticed that it's been updated.  The vhost argument wasn't there the last time I looked.  Could this bug have crept in with the change?

Apr 30, 2010 at 3:59 PM

yes, there's definitely a bug in there.


Apr 30, 2010 at 4:00 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Apr 30, 2010 at 4:35 PM

Randy, can you try the DLL I attached to the 26942 workitem?

For all RewriteBase-related stuff, including the improved logging and the faulty behavior.


Apr 30, 2010 at 8:39 PM

Done.  I posted the results in the workitem.  Looks like it's halfway right.  I did see the increased detail in the logs, that's helpful.

May 1, 2010 at 8:25 PM

ok I replied on the workitem.

May 2, 2010 at 3:50 AM

Well, as I'm not an Apache expert, I think I was taking how IIRF v2.1.1.3 was behaving and assumed that's how mod_rewrite behaved, then assumed that was the correct manner.  Now that I've read more, I'm not so sure.

I should say that I did *intend* to leave the initial "/" off the output, I'll explain why in a second.

The relevant mod_rewrite doc is here - .

I think my confusion came about because IIRF v2.1.1.3 treated the base of an application at the root of the Vhost as "/" rather than blank, and I took that as correct.  Looking at the mod_rewrite docs, I think that was incorrect. Let me use some examples.  This is the way I thought it was being handled:

Application directory(relative to vhost root)                 Application Base

root                                                                        "/"

root/myapp                                                            "/myapp/"


But this is the way that v2.1.1.14 was handling it, and which may be more correct:

Application directory(relative to vhost root)                 Application Base

root                                                                        ""

root/myapp                                                            "/myapp"


In short, is the trailing slash considered part of the base or not?  And should our RewriteRule directives always output URLs that start with "/" even with RewriteBase ON?  Either way is easy enough to deal with as long as the behavior is clear.

Honestly, in reading the mod_rewrite docs, it's *not* clear there either.  The example in the doc does *not* show a trailing slash on the base, which makes me think we would need to add our own leading "/" in RewriteRule.  But numerous other examples I came across did the opposite.  It may be that it isn't really an issue in mod_rewrite as the base is completely arbitrary.  But IIS necessitates the definition, as there is a *defined* base for the Vhost.

Personally I would *not* want you to automatically prepend a "/" to the beginning if there wasn't any present (even though it's unlikely that you'd ever want that to happen), it wouldn't fit in with expected behavior.  However, it wouldn't upset me if you did, I could see the logic for doing it.

If you want, I can ask some of our University web ninjas on Monday (we have a pretty active list-serve) what their interpretation is.  And, if this helps, here's the original mod_rewrite rules that I adapted my Wordpress Mu IIRF rules from:

RewriteEngine On
RewriteBase /

#uploaded files
RewriteRule ^(.*/)?files/$ index.php [L]
RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ $1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

May 2, 2010 at 5:07 PM

Yes, Randy, the RewriteBase changed in v2.1.1.14 in the way you describe. 

Previously , RewriteBase was "/" for the root vdir, and   "/whatever" for child vdirs.  But this was inconsistent because I could not count on the base ending in a slash, or not ending in a slash.  As a result in v2.1.1.3 I had to do special handling to the slashes, and it was error prone and felt hacky.  So the answer was to make it consistent, and that meant, either the base must end in a slash in both cases (root vdir and child vdir), or the base must not end in a slash.  That's what I tried to do in v2.1.1.14, and I picked the latter option.

This means that in v2.1.1.14, the base for the root is "" and for child vdirs, it is "/whatever". 

In that case, the result of a RewriteRule should always begin with a slash.   I like this because it is consistent with the shape of the url path when it arrives into IIRF - it always has a leading slash. Also it's consistent with HTTP, which says that URL paths start with /.   It is also consistent with the behavior of IIRF if RewriteBase is OFF. 

I'm inclined to agree with you on the question of auto-prepending a slash where it is missing.  I'd rather make it explicit.  I don't know why.

And, about your suggestion, yes!  I wouldn't mind getting more input on this issue from people who know and use Apache.


May 2, 2010 at 7:38 PM

Good, thanks for the clarification!

I will ask on Monday for an answer, but I think your solution is a good one.  It's a subtle distinction, but as long as it's defined, it's easy enough to work with.