Welcome to WebmasterWorld Guest from 54.227.1.130

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Rewrite help - excluding a url from the rewritecond

     

akreider

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

10+ Year Member



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]

</IfModule>

sublime1

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

10+ Year Member



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=").

Tom

g1smd

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.

akreider

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

10+ Year Member



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.

g1smd

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.

jdMorgan

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

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



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?

Jim
 

Featured Threads

Hot Threads This Week

Hot Threads This Month