homepage Welcome to WebmasterWorld Guest from 54.205.52.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Excluding a folder from re-write rules
PumpkinHead




msg:1495881
 2:49 pm on Oct 25, 2005 (gmt 0)

Hi all,

I'm using the following code to rewrite a few urls:

RewriteEngine on
RewriteRule ^([^_]+)_([^_]+)/([^_]+)_([^_]+)/([^_]+)_([^_]+)/ /index.php?$1=$2&$3=$4&$5=$6 [L]
RewriteRule ^([^_]+)_([^_]+)/([^_]+)_([^_]+)/ /index.php?$1=$2&$3=$4 [L]
RewriteRule ^([^_]+)_([^_]+)/ /index.php?$1=$2 [L]
RewriteRule ^index\.html$ /index.php [L]

This code is found in the root folder (www.mydomain.com/) but I also have some forums installed (www.mydomain.com/forums/) which is causing problems as the re-write rule seems to apply to lower level folders too.

How can I exclude my forums/ folder from the re-write rules?

Hope someone can help,

PH.

 

jdMorgan




msg:1495882
 4:29 pm on Oct 25, 2005 (gmt 0)

Just add

RewriteCond %{REQUEST_URI} !^/forums/

ahead of your other conditions.

Jim

PumpkinHead




msg:1495883
 4:40 pm on Oct 25, 2005 (gmt 0)

Hi,

I've just done this but i'm still getting problems?

I'm using PHPbb and all images are fine except where the folder name is seperated by an underscore...

templates/subSilver/images/lang_english/post.gif

So all images that are in folder "lang_english" do not display because of the re-write.

My current code...

RewriteEngine on

RewriteCond %{REQUEST_URI}!^/help/
RewriteRule ^([^_]+)_([^_]+)/([^_]+)_([^_]+)/([^_]+)_([^_]+)/ /index.php?$1=$2&$3=$4&$5=$6 [L]
RewriteRule ^([^_]+)_([^_]+)/([^_]+)_([^_]+)/ /index.php?$1=$2&$3=$4 [L]
RewriteRule ^([^_]+)_([^_]+)/ /index.php?$1=$2 [L]
RewriteRule ^index\.html$ /index.php [L]

Any more ideas?

jdMorgan




msg:1495884
 5:06 pm on Oct 25, 2005 (gmt 0)

You'll need to think about what you do and don't want to rewrite then, and come up with a comprehensive list.

Remember that it is the client (browser) that requests images, CSS, external JS, etc., and that it requests them by the URLs where *it thinks* they are. So, if you are using relative links, the browser will build the link from the URL it sees (in the address bar) for the current page, and not using the internally-rewritten URL, which it can't see.

I'm not sure if your problem is that these broken images are being rewritten when they should not be, or if they need to be rewritten and are not being rewritten. But either way, you need to tightly define what is and is not to be rewritten, and then modify the code to do that.

You must define the problem in terms related to the URLs. For example, "Don't rewrite if the URL ends in '.gif'" or "Rewrite if the URL contains underscores but no slashes, and only if it ends with '.html'" -- stuff like that. You can base the decision on the types of characters in the URL, the filetype of the URL, the number of slashes in the URL -- a whole host of patterns that can be tested for. But it's all based on the URLs, so it can be difficult if your URLs are not laid out on a well-defined 'plan.'

In case this is a simpler question than I've addressed, to prevent .gif files from being rewritten, just add that to your /help/ exclusion:

# Do not rewrite if path starts with "/help/" or ends with ".gif"
RewriteCond %{REQUEST_URI} !(^/help/¦\.gif$)

Replace the broken pipe "¦" symbols with solid pipes from your keyboard.

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved