.htaccess not working

Topics: Developer Forum
Apr 27, 2010 at 2:41 PM

I have an .htaccess that works on linux that do the next

<tt>RewriteEngine on</tt>
<tt>    </tt>
<tt>RewriteCond %{QUERY_STRING} or_navigation</tt>
<tt>RewriteRule .* - [L]</tt>

<tt>RewriteCond %{REQUEST_METHOD} ^GET$</tt>
<tt>RewriteCond %{QUERY_STRING} traducir=([^&]+)</tt>
<tt>RewriteCond %{QUERY_STRING} !inurl</tt>
<tt>RewriteRule ^.*$ http://examplo.com/browser.php?inurl=%{HTTP_HOST}%{REQUEST_URI} [P,L,QSA]</tt>

<tt>RewriteCond %{REMOTE_ADDR} !^192.168.0.1$</tt>
<tt>RewriteCond %{HTTP_REFERER} traducir=([^&]+)</tt>
<tt>RewriteRule ^(.*\.(php|html|htm|phtml|cgi|pl)|.*/)$ $1?traducir=%1  [QSA,R,L]</tt>

 

its possible to do the same in windows with Ionics Isapi Rewrite Filter?

Coordinator
Apr 27, 2010 at 5:48 PM
Edited Apr 27, 2010 at 5:50 PM

yes, but

  • In IIRF, the P modifier isn't supported on RewriteRule.  You can use the ProxyPass directive instead. 
  • In IIRF, The % char is not used by default for back-references to captures from RewriteCond.  You need to use *, or specify the CondSubstringBackrefFlag directive.

so:

RewriteEngine on
CondSubstringBackrefFlag %

RewriteCond %{QUERY_STRING} or_navigation
RewriteRule .* - [L]

RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{QUERY_STRING} traducir=([^&]+)
RewriteCond %{QUERY_STRING} !inurl
ProxyPass ^.*$ http://examplo.com/browser.php?inurl=%{HTTP_HOST}%{REQUEST_URI} [QSA]

RewriteCond %{REMOTE_ADDR} !^192.168.0.1$
RewriteCond %{HTTP_REFERER} traducir=([^&]+)
RewriteRule ^(.*\.(php|html|htm|phtml|cgi|pl)|.*/)$ $1?traducir=%1  [QSA,R]

Because of the use of the P flag in one of your rules, you would have seen an error or warning in the log file if you had checked.

The differences between .htaccess and IIRF syntax are summarized in the IIRF documentation.

 

Apr 28, 2010 at 12:09 PM
Edited Apr 28, 2010 at 12:24 PM

Hello,

Thank you very much for your help! I’ve tried with the code you sent me but I don’t get any results when I access http://mydomain.com/a.html?traducir=es-en I should get the value to be obtained when executing the URL:

http://example.com/browser.php?inurl=mydomain.com/a.html&traducir=es-en

Also, I see that the value of the REQUEST_URI parameter is not set in the call of the url to the proxy

my Log file says:

 

    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: actual log file 'c:\tmp\.4108.log'
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: ini file: 'C:\mydomain.com\www\Iirf.ini'
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: ini file timestamp: 2010/04/28 12:42:41 Romance Daylight Time
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: line   4: LogLevel = 3
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: line   7: CondSubstringBackrefFlag %
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: setting CondSubstringBackrefFlag to '%'
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: line   9: RewriteCond   %{QUERY_STRING}  navegacion_original
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: line  10: RewriteRule (rule 1)  '.*'  '-'      [L]
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: line  12: RewriteCond   %{REQUEST_METHOD}  ^GET$
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: line  13: RewriteCond   %{QUERY_STRING}  traducir=([^&]+)
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: line  14: RewriteCond   %{QUERY_STRING}  !inurl
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: line  15: ProxyPass (rule 2)  '^.*$'  'http://example.com/browser.php?inurl=%{HTTP_HOST}%{REQUEST_URI}'    [QSA]
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: line  17: RewriteCond   %{REMOTE_ADDR}  !^82.98.146.45$
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: line  18: RewriteCond   %{HTTP_REFERER}  traducir=([^&]+)
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: line  19: RewriteRule (rule 3)  '^(.*\.(php|html|htm|phtml|cgi|pl)|.*/)$'  '$1?traducir=%1'  [QSA,R]
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: ERROR: line  19: DO NOT USE [R] with RewriteRule - use RedirectRule instead!
    Wed Apr 28 12:44:03 -  4888 - ReadSiteConfig: Done reading, found 2 rules (1 errors, 0 warnings) on 20 lines
    Wed Apr 28 12:44:03 -  4888 - HttpFilterProc: SF_NOTIFY_URL_MAP
    Wed Apr 28 12:44:03 -  4888 - HttpFilterProc: cfg= 0x01D953F0
    Wed Apr 28 12:44:03 -  4888 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
    Wed Apr 28 12:44:03 -  4888 - DoRewrites
    Wed Apr 28 12:44:03 -  4888 - DoRewrites: Url (no decoding): '/a.html?traducir=es-en'
    Wed Apr 28 12:44:03 -  4888 - EvaluateRules: depth=0
    Wed Apr 28 12:44:03 -  4888 - EvaluateRules: Rule 1 : 1 matches
    Wed Apr 28 12:44:03 -  4888 - EvalCondition: Cond %{QUERY_STRING} navegacion_original => FALSE
    Wed Apr 28 12:44:03 -  4888 - EvalConditionList: rule 1, FALSE, Rule does not apply
    Wed Apr 28 12:44:03 -  4888 - EvaluateRules: Rule 2 : 1 matches
    Wed Apr 28 12:44:03 -  4888 - EvalCondition: Cond %{REQUEST_METHOD} ^GET$ => TRUE
    Wed Apr 28 12:44:03 -  4888 - EvalCondition: Cond %{QUERY_STRING} traducir=([^&]+) => TRUE
    Wed Apr 28 12:44:03 -  4888 - EvalCondition: Cond %{QUERY_STRING} !inurl => TRUE
    Wed Apr 28 12:44:03 -  4888 - EvalConditionList: rule 2, TRUE, Rule will apply
    Wed Apr 28 12:44:03 -  4888 - GetServerVariable: cannot find that variable
    Wed Apr 28 12:44:03 -  4888 - EvaluateRules: Result (length 93): http://example.com/browser.php?inurl=mydomain.comREQUEST_URI
    Wed Apr 28 12:44:03 -  4888 - EvaluateRules: returning 999
    Wed Apr 28 12:44:03 -  4888 - DoRewrites: Proxy to: 'http://example.com/browser.php?inurl=mydomain.comREQUEST_URI&traducir=es-en'
    Wed Apr 28 12:44:03 -  4888 - ProxyRequest: http://example.com/browser.php?inurl=mydomain.comREQUEST_URI&traducir=es-en
    Wed Apr 28 12:44:03 -  4888 - DoRewrites: Proxy complete: 0 chunks, 0 bytes'
    Wed Apr 28 12:44:03 -  4888 - HttpFilterProc: SF_NOTIFY_LOG


The code for file IIRF.ini is as follows:

    RewriteEngine on

    RewriteLog  c:\tmp\
    RewriteLogLevel 3


    CondSubstringBackrefFlag %

    RewriteCond %{QUERY_STRING} navegacion_original
    RewriteRule .* - [L]

    RewriteCond %{REQUEST_METHOD} ^GET$
    RewriteCond %{QUERY_STRING} traducir=([^&]+)
    RewriteCond %{QUERY_STRING} !inurl
    ProxyPass ^.*$ http://example.com/browser.php?inurl=%{HTTP_HOST}%{REQUEST_URI} [QSA]

    RewriteCond %{REMOTE_ADDR} !^192.168.0.101$
    RewriteCond %{HTTP_REFERER} traducir=([^&]+)
    RewriteRule ^(.*\.(php|html|htm|phtml|cgi|pl)|.*/)$ $1?traducir=%1  [QSA,R]

Thanks in advance for your help!

 

Coordinator
Apr 28, 2010 at 4:48 PM

ah, yes, an oversight on my part.

The reference to REQUEST_URI won't work, in IIRF V2.1.1.11 or below.

If you get IIRF V2.1.1.12, it should work properly.

Apr 29, 2010 at 12:32 PM

Thanks a lot for your help!

it works great with IIRF V2.1.1.14

thanks again :-)

 

Coordinator
Apr 29, 2010 at 5:56 PM

Super, glad it helped.  Thanks for the note.