I (almost) give up ... lol

Topics: Developer Forum, Project Management Forum, User Forum
Aug 17, 2009 at 5:56 AM
Edited Aug 17, 2009 at 5:58 AM

Greetings,

I am lost. I just spent 8 hours trying to make the following .htaccess file work.

============
Original .htaccess file - does not work
============ 

Options -MultiViews

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !/_af/_af.php

RewriteCond %{REQUEST_FILENAME} !/images/.*

RewriteCond %{REQUEST_FILENAME} !.*.xml$

RewriteCond %{REQUEST_FILENAME} !.*.html$

RewriteCond %{REQUEST_FILENAME} !.*.png$

RewriteCond %{REQUEST_FILENAME} !.*.gif$

RewriteCond %{REQUEST_FILENAME} !.*.jpg$

RewriteCond %{REQUEST_FILENAME} !.*.swf$

RewriteCond %{REQUEST_FILENAME} !.*.css$

RewriteCond %{REQUEST_FILENAME} !.*.js$

RewriteCond %{REQUEST_FILENAME} !.*.htm$

RewriteCond %{REQUEST_FILENAME} !.*.txt$

RewriteCond %{REQUEST_FILENAME} !phpinfo.php$

RewriteCond %{REQUEST_FILENAME} !test.php$

RewriteRule ^(.*)/?$ /_af/_af.php?a1=$1&%{QUERY_STRING} [L]

 

============
IsapiRewrite4.ini - Does not work
============
# Options -MultiViews
# RewriteEngine on
RewriteEngine ON
StatusUrl /iirfStatus
RewriteLog c:\logs\iirf
RewriteLogLevel 3
RewriteCond %{REQUEST_FILENAME} !/_af/_af.php$
RewriteCond %{REQUEST_FILENAME} !/images/.*$
RewriteCond %{REQUEST_FILENAME} !.*.xml$
RewriteCond %{REQUEST_FILENAME} !.*.html$
RewriteCond %{REQUEST_FILENAME} !.*.png$
RewriteCond %{REQUEST_FILENAME} !.*.gif$
RewriteCond %{REQUEST_FILENAME} !.*.jpg$
RewriteCond %{REQUEST_FILENAME} !.*.swf$
RewriteCond %{REQUEST_FILENAME} !.*.css$
RewriteCond %{REQUEST_FILENAME} !.*.js$
RewriteCond %{REQUEST_FILENAME} !.*.htm$
RewriteCond %{REQUEST_FILENAME} !.*.txt$
RewriteCond %{REQUEST_FILENAME} !phpinfo.php$
RewriteCond %{REQUEST_FILENAME} !test.php$
RewriteRule ^/([^\./]+)$ /_af/_af.php?a1=$1&%{QUERY_STRING} [L]
 
  
============
IsapiRewrite4.ini - Does WORK
============
# Options -MultiViews
# RewriteEngine on
RewriteEngine ON
StatusUrl /iirfStatus
RewriteLog c:\logs\iirf
RewriteLogLevel 3
RewriteRule ^/([^\./]+)$ /_af/_af.php?a1=$1&%{QUERY_STRING} [L]
================================

Please help ... I do not know much about .htaccess files ... the last time I worked on one was 11 years ago.

Aug 17, 2009 at 6:25 AM
Edited Aug 17, 2009 at 6:27 AM

I have just tried this:

------ 

RewriteEngi---ne ON
StatusUrl /iirfStatus
RewriteLog c:\logs\iirf
Rewr---iteLogLevel 3
# RewriteCond $1 !^(/_af/_af.php|phpinfo.php|test.php|images|(.*).xml|(.*).html|(.*).png|(.*).gif|(.*).jpg|(.*).swf|(.*).css|(.*).js|(.*).htm|(.*).txt)
RewriteRule ^/([^\./]+)$ /_af/_af.php?a1=$1&%{QUERY_STRING} [L]

RewriteEngine ON

StatusUrl /iirfStatus

RewriteLog c:\logs\iirf

RewriteLogLevel 3

RewriteCond $1 !^(/_af/_af.php|phpinfo.php|test.php|images|(.*).xml|(.*).html|(.*).png|(.*).gif|(.*).jpg|(.*).swf|(.*).css|(.*).js|(.*).htm|(.*).txt)

RewriteRule ^/([^\./]+)$ /_af/_af.php?a1=$1&%{QUERY_STRING} [L]

 

-----

it does not work either

 

Coordinator
Aug 17, 2009 at 7:40 AM

Maybe try something simpler?

First thing you should know is that the !^something syntax does not work for IIRF.  It's a regex, a proper regex, so if you want to negate something you can do (?!whatever). 

Also, you have some really long RewriteCond statements that are hard to read and visually verify. I would suggest something a little easier to write, maintain, and understand. Break down the rules you want into pieces. Something more like:

RewriteLog c:\logs\iirf
RewriteLogLevel 3
RewriteEngine ON
StatusUrl /iirfStatus

# if the url is  /_af/_af.php, don't rewrite
RewriteRule ^/_af/_af\.php  -   [L]

# if the url is  /phpinfo.php, don't rewrite
RewriteRule phpinfp\.php  -   [L]

# this rule applies to any request not ending in one of these suffixes.
RewriteCond $1  ^.+(?!xml|html|png|gif|jpg|swf|css|js|htm|txt)$
# Rewrite to /_af/_af.php with the orig request path as a querystring param, and
# appending the original querystring.
RewriteRule ^/([^\?]+) /_af/_af.php?a1=$1 [L,QSA]

There are three rules. The first two just do "no rewrite", when the pattern applies. The dash ( - ) signifies no rewrite. The [L] modifier says "apply no more rules for this URL. This has the effect of eliminating URLs that match those patterns, from the final rule.

The final rule has a condition attached. It rewrites to /_af/_af.php when the rule and condition applies.

The RewriteRule pattern ^/([^\?]+) matches a string beginning with slash, followed by a sequence of 1 or more characters that are not question marks. For any bare url (with no querystring) it will match the entire URL path (not the scheme, server name or port, obviously). For a URL with a query string, it matches just the bare URL, and does not capture the query string. The url path is captured into $1. This is then applied as a querystring param named a1. The QSA thing tells IIRF to append the original query string, to the result of the rewrite.

This rewrite occurs only when the RewriteCond evaluates to true, and in this case, the condition is true when the $1 (which I said is the URL path not including the query string), does not end in xml, html, and etc.

This may or may not be what you want, but it is closer to what you want than what you had.

 

 

Aug 17, 2009 at 8:10 AM

PERFECT ... Nice.

THHHHHHHHHHHHAAAAANK YOU!!!

You saved my *ss.

Aug 17, 2009 at 8:11 AM

btw ... the original code was not mine ... it is a site tha Iam migrating over to windows.

Coordinator
Aug 17, 2009 at 8:32 AM

I'm glad it works for you.

It may not be truly perfect, be sure to test everything.

 

Aug 17, 2009 at 8:35 AM
Edited Aug 17, 2009 at 8:36 AM

Everything I have tested so far seems to work fine.

Aug 17, 2009 at 9:41 AM

i jumped the gun.

 

RewriteCond $1  ^.+(?!xml|html|png|gif|jpg|swf|css|js|htm|txt)$

does not seems to work ... it looked like it wasing working at first (it was most likely using my cache).

:(

 

Aug 17, 2009 at 10:26 AM

http://74.62.242.146/index25.html

Coordinator
Aug 17, 2009 at 4:02 PM

right, like I said, you have to test it.  Check the IIRF logs and you'll see which URLs are being received but not rewritten in the way you want.

 

Aug 18, 2009 at 2:57 AM

will do ... ty