Forum Moderators: phranque
The rewrite rules work on the url but the parameter list and the values do not get rewriteen.
ex:
[myse<script>rver.com...]
will change to
[myserver.com...]
& I want it to work like this...
[myserver.com...]
Any Ideas?
Thanks
Thanks, these are the rules...
<IfModule mod_rewrite.c>
RewriteEngine ON
RewriteLog rewrite.log
RewriteLogLevel 9
RewriteCond %{HTTP_HOST} ^.*$ [NC]
RewriteRule ^/(.*)<SCRIPT>(.*)$ /$1$2 [PT]
RewriteRule ^/(.*)<script>(.*)$ /$1$2 [PT]
RewriteRule ^/(.*)<Script>(.*)$ /$1$2 [N]
RewriteCond %{QUERY_STRING} ^.*$[NC]
RewriteRule ^/(.*)<SCRIPT>(.*)$ /$1$2 [PT]
RewriteRule ^/(.*)<script>(.*)$ /$1$2 [PT]
RewriteRule ^/(.*)<Script>(.*)$ /$1$2 [PT]
</IfModule>
Umakanth
I guess I don't understand your question. The first and second group of rules appear to be redundant, since any value will be accepted for HTTP_HOST and QUERY_STRING. Also, a RewriteCond only applies to the single RewriteRule that follows it, so I do not understand what your code is intended to accomplish.
Can you ask a more specific question related to your code, and provide more examples of the requested URLs and the desired output URLs?
Jim
This is what I had initially in the httpd.conf file.
<IfModule mod_rewrite.c>
RewriteEngine ON
RewriteLog rewrite.log
RewriteLogLevel 9
RewriteCond %{HTTP_HOST} ^.*$ [NC]
RewriteRule ^/(.*)<SCRIPT>(.*)$ /$1$2 [PT]
RewriteRule ^/(.*)<script>(.*)$ /$1$2 [PT]
</IfModule>
Currently these rules are working on part of the url
i.e. [myse<script>rver.com?p_id=8218...]
rewriteen to [myserver.com?p_id=8218...]
What is not working is if the url is
[myserver.com?p_i<script>d=8218...]
It should change to
Let me know if you have questions.
Thanks
Umakanth
RewriteRule ^/(.*)<SCRIPT>(.*)$ /$1$2 [PT]
RewriteRule ^/(.*)<script>(.*)$ /$1$2 [PT]
RewriteRule ^/(.*)<script>(.*)$ /$1$2 [[b]NC,[/b]PT]
RewriteCond %{QUERY_STRING} ^(.*)<script>(.*)$ [NC]
RewruteRule ^/(.*)$ /$1?%1%2 [PT]
Also, if you need to eliminate these corrupted URLs from search engine listings, then generate an external 301 redirect, instead of immediately invoking the content-handler.
Jim
There's also the case where both the URL and the query string contain "<script>", and this case is not handled by the code I posted, either. How you fix that depends on whether you want to use [N] or not. And that depends on how many times per hour/day you get a request for these malformed URLs.
There are dozens of ways to solve the problem, but the most efficient way depends on whether performance is an issue -- I mean, you can have performance efficiency or code simplicity.
Jim
My requirements is to filter out a list of characters/words from incoming url and we use apache web server.
Is there an alternate soluction than mod_rewrite to acheive this, maybe block such url's or a standard
procedure/function that can process each incoming urls
Thanks again
Umakanth
Block them -- Return 403-Forbidden response.
Rewrite them -- Return alternate content page(s).
Redirect them -- Redirect to a different URL or URLs.
Mask them -- Internally rewrite them to the correct local URL-path, pretending there was no error in the URL.
Correct them -- Externally redirect to the correct URL (helps to correct search engine listing URLs).
All of these solutions could be implemented with mod_rewrite, but mod_rewrite is somewhat limited in handling multiple corrections per requested URL. If all of your content is generated by a php or CGI script, then perhaps you could do the corrections in the script more easily.
Jim
I am trying to avoid going thru that big a change and trying to implement something on the server. Is there an alternative to mod_rewrite on apache server OR is there a greater performance issue if we implement mod_rewrite to look for multiple instances of these characters?
Thanks
Umakanth
Other than using a script? - No, I don't think so.
> OR is there a greater performance issue if we implement mod_rewrite to look for multiple instances of these characters?
The performance penalty is (number of URL corrections needed per unit time).
I'm afraid that I can't offer much more advice except to say that it is time to code this up and test it. I could predict success or failure, but I do not know how many bad URL requests you get per second, how much overall traffic your site gets, how fast your server and backbone connection are, or any of the other hundreds of factors that will affect the outcome. So, regardless of what I predict, there is only a 50% chance I'll be right. It's time for testing.
Hopefully, you know how to eliminate the source of these bad URLs. In that case, this problem and any related performance penalties will be limited to a few months' time. In the meantime, all you can do is implement a fix and try to performance-optimize it to minimize the interim impact.
The more precise your regex patterns, the faster the code can be processed. As noted above, avoid the use of ambiguous ^(.*)xyz(.*)$ -type patterns if at all possible.
Jim
Following is the code
RewriteEngine ON
RewriteLog D:\Apache\logs\rewrite.txt
RewriteLogLevel 1
RewriteRule ^/(.*)<script>(.*)$ /$1$2 [NC]
RewriteRule ^/(.*)<script>(.*)$ /$1$2 [NC,PT]
RewriteCond %{QUERY_STRING} ^(.*)<script>(.*)$ [NC]
RewriteRule ^/(.*)$ /$1?%1%2 [PT]
Thanks
Umakanth
RewriteEngine ON
RewriteLog D:\Apache\logs\rewrite.txt
RewriteLogLevel 1
# Strip URLs
RewriteRule ^/(.*)<script>(.*)$ /$1$2 [NC,E=Stripped:yes,N]
# Strip query strings
RewriteCond %{QUERY_STRING} ^(.*)<script>(.*)$ [NC]
RewriteRule ^/(.*)$ /$1?%1%2 [E=Stripped:yes,N]
# Pass through stripped requests
RewriteCond %{ENV:Stripped} ^yes$
RewriteRule .* - [PT,L]
I *am* sure it will be slow if you receive a lot of these requests.
Jim
Last question if we need to add more filter characters then can I add it like this, sorry new to regular expressions maybe a silly question?
<IfModule mod_rewrite.c>
RewriteEngine ON
RewriteLog D:\Apache\logs\rewrite.txt
RewriteLogLevel 1
# Strip URLs
RewriteRule ^/(.*)<script>(.*)$ /$1$2 [NC,E=Stripped:yes,N]
RewriteRule ^/(.*)<\/script>(.*)$ /$1$2 [NC,E=Stripped:yes,N]
# Strip query strings
RewriteCond %{QUERY_STRING} ^(.*)<script>(.*)$ [NC]
RewriteRule ^/(.*)$ /$1?%1%2 [E=Stripped:yes,N]
# Pass through stripped requests
RewriteCond %{ENV:Stripped} ^yes$
RewriteRule .* - [PT,L]
</IfModule>
RewriteRule ^/(.*)[b]</?s[/b]cript>(.*)$ /$1$2 [NC,E=Stripped:yes,N]
And again, if all filtered strings start with "<", then use a more specific pattern:
RewriteRule ^/([^<]*)</?script>(.*)$ /$1$2 [NC,E=Stripped:yes,N]
Jim
RewriteRule ^/([^<]*)</?script>(.*)$ /$1$2 [NC,E=Stripped:yes,N]
and what is interesting is the below condition works for querystring but not for the main url
RewriteRule ^/(.*)</script>(.*)$ /$1$2 [NC,E=Stripped:yes,N]
I tried with "/?" also initially.
Would you suggest a good book or a reference link on the web to get familier with regular expressions on apache, you have been really helpful but I need to get a hang of it too.
Thanks again
Umakanth
Sure, see our forum charter [webmasterworld.com], or search for "regular expressions tutorial" or "regex tutorial".
Jim
Remember, to avoid insanity, decide what you will *accept* in posted data and filter everything else; Don't try to think up every possible thing that you might want to reject. The latter approach can be a maintenance nightmare, and can lead to madness.
Jim
Installation on windows apache server was a little tricky because of the compiler and header files but the module itself works wonderfully.
Keep up the good work.
Regards
Umakanth