Welcome to WebmasterWorld Guest from 54.166.114.43

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Excluding a folder from re-write rules

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

10+ Year Member



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.

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Just add

RewriteCond %{REQUEST_URI} !^/forums/

ahead of your other conditions.

Jim

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

10+ Year Member



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?

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month