Forum Moderators: phranque
i got stuck with a rewrite Rule.
My Use case goes like this:
We have a jsp on our server that should not be called without parameter.
So i want to have a rewrite rule that works like this, when this jsp is called without a parameter he will bring up a 403 Error.
In this case /dir1/dir2/dir3/dir4/calc.jsp is a bad url
/dir1/dir2/dir3/dir4/calc.jsp?id=1&lang=en is a good url
My effort until now was something like:
RewriteEngine on
RewriteLog /tmp/rewritel.log
RewriteLogLevel 9
RewriteRule "^/dir1/dir2/dir3/dir4/calc\.jsp$" "-" "[F]"
#RewriteRule "/dir1/dir2/dir3/dir4/calc\.jsp$" "-" "[F]"
Now there is the step missing where i can say if a parameter is passed starting with a ? it is ok.
I tried rewrite rules like
RewriteRule "/dir1/dir2/dir3/dir4/calc\.jsp$(!(\?.)*)" "-" "[F]"
RewriteRule "/dir1/dir2/dir3/dir4/calc\.jsp$([\?.]*)" "-" "[F]"
But nothing works. Also the search for block urls with paramter leads me to a solution....
I would appreciate your hints and tipps.
RewriteEngine On
#
RewriteCond %{THE_REQUEST} ![?]
RewriteCond %{REQUEST_URI} ^/calc\.jsp [NC]
RewriteRule .* - [F,L]
Alternatively, you might wish to use that:
RewriteEngine On
#
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} ^/calc\.jsp [NC]
RewriteRule .* - [F,L]
Depends on if you wish to allow 'empty' query string or no query string at all!
Now i solved it like this:
i put it into the virtual host definition httpd.conf for the service. Due to the conditions are locigal AND i have put the rule for detecting the ? after the URI Condition to avoid apache getting into a performace problem when fullfilling the requests.
Here is the rewrite rule that works:
RewriteEngine on
RewriteLog /tmp/rlogs.log
RewriteLogLevel 9
RewriteCond %{REQUEST_URI} "^/dir1/dir2/dir3/dir4/calc\.jsp" [NC]
RewriteCond %{THE_REQUEST} "![?]"
RewriteRule ".*" "-" "[F]"
Thanks for all your support
Roadrunner99