homepage Welcome to WebmasterWorld Guest from
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

Rewrite help - excluding a url from the rewritecond

 7:28 pm on Oct 13, 2010 (gmt 0)

I have a rewriterule for a tinyurl system that I made for a subdirectory of our website.

Our tinyurl looks like: www.domain.org/t=xyz123

RewriteRule t=(.*)$ /map/server-test/tiny.php?gsKey=$1

However, when I installed Drupal in the main website - the tinyurl stopped working.

I tried to add a RewriteCond so that Drupal wouldn't rewrite the tinyurl, but it doesn't work.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule t=(.*)$ /map/server-test/tiny.php?gsKey=$1

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=t=(.*)
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]




 2:20 pm on Oct 15, 2010 (gmt 0)

Double-check that last RewriteRule -- should the "index.php" be "/index.php"? Also, the $1 in that rule refers to the part captured in the earlier part of the line. %1 would return the part captured in the previous RewriteCond (the value after "t=").



 6:04 pm on Oct 15, 2010 (gmt 0)

An [L] flag on the end of the first Rule would stop processing passing through to the second rule.

However, be aware that = is not a valid character for use in the path part of a URL. It is only valid in the query string part of a URL; i.e. after a question mark.

Additionally, move the -d and -f exists checks so that they are third and fourth not first and second. This will substantially speed up the mod_rewrite processing for non-matching URLs.


 9:53 pm on Oct 15, 2010 (gmt 0)

Thanks! The L flag worked.

I got rid of the line which I had added to try and fix things:
RewriteCond %{REQUEST_URI} !=t=(.*)

The rest is from the default Drupal .htaccess file, so I think I'll leave it as it is.


 10:08 pm on Oct 15, 2010 (gmt 0)

Do change the order of the RewriteConds. It will have a significant positive effect on the page loading speed.

This is an often discussed subject here. Consider adding another RewriteCond ahead of the -f and -d "exists" checks, one that excludes requests for images, stylesheets and scripts by extension.


 2:32 pm on Oct 16, 2010 (gmt 0)

The default Drupal code is pretty bad, so I suggest that you follow g1smd's advice and fix it.

The way they have it coded, it makes anywhere from two to four unnecessary disk accesses for every request to your server. While most Webmasters will see a performance increase on the order of 5 or 6% by making the simple fix he suggests, others may see a significantly higher improvement - especially on very-busy shared-hosting servers. Plus your hard drives will last longer.

By simply avoiding the disk checks until it is known that they are really necessary, you can speed up your page loads, avoid costly server down-time, and defer the need to upgrade to a higher-performance (and higher-priced) server.

# Rewrite URL-paths of the form '/x' to the filepath+query 'index.php?q=x'.
RewriteCond $1 !((\.(gif|jpe?g|png|ico|css|js)|^index\.php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [QSA,L]

I suggest that you try this, clear your cache, and then visit the slowest-loading page on your site. Better?


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