Forum Moderators: phranque

Message Too Old, No Replies

RewriteMap Question

Is the fallback url necessary after the '¦' pipe?

         

5x54u

10:04 pm on Feb 24, 2009 (gmt 0)

10+ Year Member



RewriteCond %{REQUEST_URI} !-U
RewriteRule ^(.*) ${providers:$1¦}

The above code looks ahead to see if a directory will throw a 404 and then uses the providers text map. My question is, do I have to have a default fall back url after the pipe because if a directory is not found and the string is not in the providers map - i do want to throw a 404

Caterham

10:47 pm on Feb 24, 2009 (gmt 0)

10+ Year Member



The above code looks ahead to see if a directory will throw a 404

Really? -U checks only access controls via a subrequest. I don't want to go into the details, but there is no 404 prior processing the content handler (and the subrequest doesn't run the content handler of course) unless you hacked a fixup hook to return HTTP_NOT_FOUND if r->finfo.filetype is 0.

. My question is, do I have to have a default fall back url after the pipe

Yes, due to to your rule-design. An empty substitution results in a HTTP 400 bad request. Use the map lookup in a condition and check for a non-empty value like

RewriteCond ${providers:$1} ^(.+)
RewriteRule ^(.*) %1 [L]

5x54u

11:02 pm on Feb 24, 2009 (gmt 0)

10+ Year Member



That one does not work - how can I test to make sure it is seeing the map file.

This is what I have in the httpd.cof under the particular domain:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteOptions inherit
RewriteMap providers txt:/usr/local/apache2/conf/providers.map
</IfModule>

And I placed your suggestion in the .htaccess under the root of the site

Caterham

11:32 pm on Feb 24, 2009 (gmt 0)

10+ Year Member



in the .htaccess

Why? That is not only inefficient since there's absolutely no need for .htaccess files if you have access to the server config but the directory context of mod_rewrite is due to the internal redirect not so efficient and more complex, too. Avoid that by putting the rules into the httpd.conf as well.

Examine problems with a RewriteLog.