Link to home
Start Free TrialLog in
Avatar of mrperfect75000
mrperfect75000Flag for United States of America

asked on

Exempting specific files from Rewrite Engine.

I have this code right now that works...

when i type something like www.mysite.com/first_test.html 

it gives me  www.mysite.com/result.asp?kwds=first test, but it still keeps the static html(for SEO purposes)

RewriteEngine on
RewriteRule ^([0-9a-zA-Z]+)[_]([0-9a-zA-Z]+)[_]([0-9a-zA-Z]+).*$ results.asp?kwds=$1+$2+$3
RewriteEngine on
RewriteRule ^([0-9a-zA-Z]+)[_]([0-9a-zA-Z]+).*$ results.asp?kwds=$1+$2


The problem is, if for example i have a real file that is named second_test.html on my server with  content in it.  

When i type in www.mysite.com/second_test.html  ....it rightfully takes me to

www.mysite.com/result.asp?kwds=second test

Is there a way for me to exempt certain files from being excuted by this script?
So that when i type in www.mysite.com/second_test.html i get the actual file on the server not the generated page. I only want to be able to specify certain files not to be excuted by this script.

 Please help.

Thanks.
Avatar of HackneyCab
HackneyCab
Flag of United Kingdom of Great Britain and Northern Ireland image

How about a RewriteCond that checks for a set of document names:

RewriteCond %REQUEST_URI !^/path/(doc-name1|doc-name2|doc-name3)\.html$

The next RewriteRule that follows this can only execute if the REQUEST_URI is none of the following:

/path/doc-name1.html
/path/doc-name2.html
/path/doc-name3.html

You ought to be able to use this pattern to rule out a number of actual static HTML files that you don't want redirected to a script.

However, my site is small, and I'm not sure if this multi-name pattern can scale up to a large number of document names.

See the RewriteCond section in the Apache docs:

http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteCond
Avatar of shatteredstone
shatteredstone

If you want a generic rule that only rewrites if a given file does NOT exist (and it sounds like you might want that),

RewriteCond %{REQUEST_FILENAME} !-f

would test for that (inside the server configuration; insite a .htaccess it's %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} instead).

You also do not need more than one RewriteEngine on. So in the end, your ruleset would look like this :

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9a-zA-Z]+)[_]([0-9a-zA-Z]+)[_]([0-9a-zA-Z]+).*$ results.asp?kwds=$1+$2+$3
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9a-zA-Z]+)[_]([0-9a-zA-Z]+).*$ results.asp?kwds=$1+$2
SOLUTION
Avatar of HackneyCab
HackneyCab
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrperfect75000

ASKER

Thanks! If i had more than one file i want to exlude - do i have to do include each one?

Thanks for your help...
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial