Forum Moderators: phranque

Message Too Old, No Replies

No rewriting for certain file types

I want Apache to process certain file types as if there was no mod_rewrite

         

MonkeyFace

4:05 am on Oct 25, 2010 (gmt 0)

10+ Year Member



This is from the Kohana .htaccess file


# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]


I would like Apache to request for .xml and .html files to process as if there was no mod_rewrite. What's the way to do it?

jdMorgan

11:47 am on Oct 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I would like [Apache to process requests for] .xml and .html files as if there was no mod_rewrite. What's the way to do it?

Do you mean physical .xml and .html files, or do you mean URLs ending with .xml or .html? These are not at all the same thing.

With the exception of your "application and system files", requests for URLs which resolve to physically-existing files or directories are not rewritten by your code.

The simple answer to your question is to precede this code with a "skip rule" or a "quit rule," but there appear to be additional problems here, so I'd like to clarify the question.

Note that "$0" is not defined by mod_rewrite; Only $1 through $9 are defined. Further, this code will only work properly on servers with the PCRE (PERL-Compatible Regular Expressions) library installed -- that is, on Apache 2.0 and later. It will not work on Apache 1.x.

Skip rule:
 # Skip next two rules if .xml or .html URL-path is requested
RewriteRule \.(xml|html)$ - [S=2]

Quit rule:
 # Quit mod_rewrite processing if .xml or .html URL-path is requested
RewriteRule \.(xml|html)$ - [L]

Jim

MonkeyFace

8:30 pm on Oct 25, 2010 (gmt 0)

10+ Year Member



Hi jdMorgan, thanks for the response!

The abobe two rules throw a 404 for non-existent files (as required), but a 500 for existent ones. I guess we are quite close to it.

By the way, they are put right above

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

jdMorgan

9:00 pm on Oct 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As I stated, "$0" isn't documentably-valid.

Try
 RewriteRule ^(.*)$ /index.php/$1 [PT,L] 

or
 RewriteRule ^ /index.php%{REQUEST_URI} [PT,L] 

instead.

Also, if you are getting a 500-Server Error, then it would be a very good idea to look at your server error log to find out (and tell us the meaning of) what the server is complaining about. The error log will often tell you (or us) exactly what is wrong...

Jim