RewriteRule help

Author Message

Trond Åge Kvalø

Thursday 10 June 2004 7:10:53 am

I tried to use the following rewrite rule on my site:

#RewriteRule !(^/design|^/var/.*/storage|^/var/storage|^/var/.*/cache|^/var/cache|^/extension/.*/design|^/kernel/setup/packages).*\.(gif|css|jpg|png|jar|js|ico|pdf|swf)$ /index.php

In my site I use an <iframe> for showing a JavaScript based navigation-system (I know, I know....).

When using the above Rewrite rule, I get the site frontpage in the iframe instead of the navigation menu.

I'm no expert on Rewrite rules in Apache, so can anyone please tell me why this happens?

best regards
trondåge

trondåge

Bruce Morrison

Thursday 10 June 2004 4:31:46 pm

Whats the URL used in the iframe?

Cheers
Bruce http://www.designit.com.au

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Trond Åge Kvalø

Friday 11 June 2004 1:29:33 am

Hi Bruce.

Here's the beginning of my iframe:

<iframe id="navigationContainer" name="navigationContainer" src="/snakeMenu/snakeMenu.html" 

hmmmm.... perhaps I need to add the /snakeMenu directory to my rewrite rule?

I also have some other nonstandard directories in my eZ publish directory. I have for instance all my javascripts placed in a directory called javascript. Do I need to include those non-standard directories as well?

best regards
trondåge

trondåge

Trond Åge Kvalø

Friday 11 June 2004 5:11:59 am

Ok, after reading a little in mastering Regular Expressions by Jeffrey Friedl (O'Reilly), here's what I've come up with:

If I've understood this correctly "|" means OR inside parenthesis, so the rewrite rule basically states that whenever the beginning of the URL is one of the expressions OR'ed in the first parenthesis, followed by any charachters and then a dot, and the end of URL is one of the expressions in the last parenthesis, the browser is redirected to /index.php

If this is correct, I'm even more puzzled. Because the URL in the iframe shouldn't be redirected then since it's path is not in the first parenthesis.. or am I misunderstanding completely?

best regards
trondåge

trondåge

Tobias Persson

Friday 11 June 2004 5:58:14 am

I think the first '!' mean not

So everything that is do not follow the regular expression gets rewritten to index.php

Trond Åge Kvalø

Friday 11 June 2004 6:06:29 am

Hi Tobias

Why of course, didn't see that because of the line wrapping :-)

So that means that the /snakeMenu directory should be included in the ignored paths, right?

Thanks :-)

best regards
trondåge

trondåge

Tobias Persson

Friday 11 June 2004 6:23:58 am

I think (guess) that you should add ^/snakeMenu in the first parenthes and html to the last one.

Bruce Morrison

Friday 11 June 2004 3:45:27 pm

I find it easiest to add a rewrite rule before that ezpub one.

So you would end up with something like:

RewriteRule /snakeMenu/snakeMenu.html %{DOCUMENT_ROOT}/snakeMenu/snakeMenu.html [L]
RewriteRule !(^/design|^/var/.*/storage|^/var/storage|^/var/.*/cache|^/var/cache|^/extension/.*/design|^/kernel/setup/packages).*\.(gif|css|jpg|png|jar|js|ico|pdf|swf)$ /index.php

The [L] at the end of the first rule says "Don't process any more rules".

Cheers
Bruce http://www.designit.com.au/

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Trond Åge Kvalø

Tuesday 15 June 2004 5:51:13 am

Thanks for the suggestion Bruce.

But why wouldn't I want to process the last rule? Is it unnecessesary?

best regards
trondåge

trondåge

Bruce Morrison

Tuesday 15 June 2004 4:37:33 pm

The first rule allows requests for the /snakeMenu/snakeMenu.html file to be returned without being passed to ez Publish (index.php). It's basically a pass through rule.

This method allows you to add "pass through" rules without making changes to the standard eZ Publish rule.

I should have added that [L] at the end of the first rules says "if this rule matches, don't process any more rules"

Cheers
Bruce http://www.designit.com.au/

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Trond Åge Kvalø

Thursday 17 June 2004 1:37:07 am

Cheers Bruce!

OK, now I understand. Made a bit of difference the first few words there :-)

Anyway, as I mentioned earlier I have a few other non-standard directories as well. I presume I could just OR these directories together with the snakeMenu directory in the first line to get things right.

Does that sound correct to you?

Best regards
trondåge

trondåge

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.