mod_rewrite rule does not work

This is a discussion on mod_rewrite rule does not work within the Apache Web Server forums, part of the Web Server and Related Forums category; I have started using mod_rewrite through .htaccess but some of the RewriteRules will not work. My .htaccess is in the ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-10-2008
Frowning Freezer
 
Posts: n/a
Default mod_rewrite rule does not work

I have started using mod_rewrite through .htaccess but some of the
RewriteRules will not work. My .htaccess is in the root of the website and
the content is:

-------------------------------------------
IndexIgnore *
RewriteEngine on

RewriteRule ^insurancepolicy/?$
php/docs/Short-Term_Insurance_Policy_Summary.pdf
RewriteRule ^sowing-resource-catalog/?$
php/docs/Sowing_Resource_Catalogue.pdf
#THESE 2 RULES WORK FINE!!

RewriteRule story\.php.*http - [F]
#this should block: http://www.domain.com/php/story.php?...mespamsite.com
#BUT DOES NOT WORK :(

RewriteRule email\.php.*http - [F]
#this should block:
http://www.domain.com/php/email.php?...mespamsite.com
#BUT DOES NOT WORK :(
-------------------------------------------

Any ideas why the two last ones don't work? I have tried all kinds of
different ways of writing the regular expression, even tried putting them in
an .htaccess file within the /php folder - but to no avail! HELP!

Allan


  #2 (permalink)  
Old 06-10-2008
phantom
 
Posts: n/a
Default Re: mod_rewrite rule does not work

"Frowning Freezer" <pub1@hverdag.dk> wrote in message
news:484e6450@news.broadpark.no...
>I have started using mod_rewrite through .htaccess but some of the
>RewriteRules will not work. My .htaccess is in the root of the website and
>the content is:

<SNIP>
> RewriteRule story\.php.*http - [F]
> #this should block:
> http://www.domain.com/php/story.php?...mespamsite.com
> #BUT DOES NOT WORK :(
>
> RewriteRule email\.php.*http - [F]
> #this should block:
> http://www.domain.com/php/email.php?...mespamsite.com
> #BUT DOES NOT WORK :(
> -------------------------------------------
>
> Any ideas why the two last ones don't work?


It doesn't work because the query string (the question mark and everything
after it) is not part of the URI you are trying to match, try
RewriteCond %{QUERY_STRING} http
RewriteRule story\.php - [F]

and
RewriteCond %{QUERY_STRING} http
RewriteRule email\.php - [F]


  #3 (permalink)  
Old 06-10-2008
Frowning Freezer
 
Posts: n/a
Default Re: mod_rewrite rule does not work

>>I have started using mod_rewrite through .htaccess but some of the
>>RewriteRules will not work. My .htaccess is in the root of the website and
>>the content is:

> <SNIP>
>> RewriteRule story\.php.*http - [F]
>> #this should block:
>> http://www.domain.com/php/story.php?...mespamsite.com
>> #BUT DOES NOT WORK :(
>>
>> RewriteRule email\.php.*http - [F]
>> #this should block:
>> http://www.domain.com/php/email.php?...mespamsite.com
>> #BUT DOES NOT WORK :(
>> -------------------------------------------
>>
>> Any ideas why the two last ones don't work?

>
> It doesn't work because the query string (the question mark and everything
> after it) is not part of the URI you are trying to match, try
> RewriteCond %{QUERY_STRING} http
> RewriteRule story\.php - [F]


Oh my, that's a bummer - had neither expected that or read that anywhere!
Then I better understand why nothing worked. But is it then not possible to
use data from the query string in the substitution string??

Allan


  #4 (permalink)  
Old 06-10-2008
phantom
 
Posts: n/a
Default Re: mod_rewrite rule does not work

"Frowning Freezer" <pub1@hverdag.dk> wrote in message
news:484e6b3b@news.broadpark.no...
>>>I have started using mod_rewrite through .htaccess but some of the
>>>RewriteRules will not work. My .htaccess is in the root of the website
>>>and the content is:

>> <SNIP>
>>> RewriteRule story\.php.*http - [F]
>>> #this should block:
>>> http://www.domain.com/php/story.php?...mespamsite.com
>>> #BUT DOES NOT WORK :(
>>>
>>> RewriteRule email\.php.*http - [F]
>>> #this should block:
>>> http://www.domain.com/php/email.php?...mespamsite.com
>>> #BUT DOES NOT WORK :(
>>> -------------------------------------------
>>>
>>> Any ideas why the two last ones don't work?

>>
>> It doesn't work because the query string (the question mark and
>> everything after it) is not part of the URI you are trying to match, try
>> RewriteCond %{QUERY_STRING} http
>> RewriteRule story\.php - [F]

>
> Oh my, that's a bummer - had neither expected that or read that anywhere!
> Then I better understand why nothing worked. But is it then not possible
> to use data from the query string in the substitution string??
>

see here:
http://httpd.apache.org/docs/2.2/mod...ml#rewritecond
RewriteCond backreferences

as am example, if you have:
RewriteCond %{QUERY_STRING} ^(.*)$
then you can specify %1 in the rule substitution for the entire query string


 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:19 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0