| This 37 message thread spans 2 pages: 37 ( [1] 2 ) > > | |
| Preventing conflicts with WP mod_rewrite code and speeding it up as well |
wheel

msg:4053975 | 8:53 pm on Jan 4, 2010 (gmt 0) | I've got wordpress installed in my root folder, and some other unrelated stuff in my /cgi-bin. When I install the wordpress permalinks htaccess in my root, stuff in my cgi-bin directory gets an access denied error message: here's my wordpress htaccess: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> And here's what's in the <directory> block for my cgi-bin in my httpd conf file: AllowOverride All Options None ExecCGI DirectoryIndex index.html AddHandler cgi-script .cgi .pl Order allow,deny Allow from all Any thoughts on what's causing my cgi-bin programs to get access denied? Or how to opt out my cgi-bin directory from the root .htaccess directives?
|
WesleyC

msg:4054040 | 10:53 pm on Jan 4, 2010 (gmt 0) | I usually use a line that looks something like this in my rewrites--it should go just above the RewriteRule line. RewriteCond $1 !^(cgi-bin¦excludedDir2¦file\.html) This allows access to /cgi-bin, /excludedDir1, /dir2, and /file.html outside of Wordpress. The problem you're running into exists because the default Wordpress .htaccess rewrites any folder or file in its directory or any subdirectory to be "routed" by its own systems in index.php--which, for security reasons, don't allow just any URL through; only ones that it expects. The line I gave above tells Apache to not direct URLs starting with the indicated folder and file names to Wordpress's handler--this should allow the browser to reach them normally.
|
wheel

msg:4054122 | 2:14 am on Jan 5, 2010 (gmt 0) | Wesley - thank you very much! That did it, and it's particularly satisfying after a day spent researching and failed attempts, to get handed a solution! thanks again.
|
WesleyC

msg:4054139 | 3:50 am on Jan 5, 2010 (gmt 0) | Not a problem! The first time I came across this particular issue, it nearly drove me up the wall until I found a forum post by some helpful soul with the answer--in fact, I believe it was on these very forums, though under a rather obscure post name.
|
jdMorgan

msg:4054591 | 4:58 pm on Jan 5, 2010 (gmt 0) | I posted this code in Supporters earlier today. But it may prove useful to lots of WP users, so I'll post it here without all the comments and discussion in that thread. Speed up your WP mod_rewrite code by a factor of more than two:
# BEGIN WordPress # RewriteEngine on # # Unless you have set a different RewriteBase preceding this point, # you may delete or comment-out the following RewriteBase directive # RewriteBase / # # if this request is for "/" or has already been rewritten to WP RewriteCond $1 ^(index\.php)?$ [OR] # or if request is for image, css, or js file RewriteCond $1 \.(gif¦jpg¦ico¦css¦js)$ [NC,OR] # or if URL resolves to existing file RewriteCond %{REQUEST_FILENAME} -f [OR] # or if URL resolves to existing directory RewriteCond %{REQUEST_FILENAME} -d # then skip the rewrite to WP RewriteRule ^(.*)$ - [S=1] # else rewrite the request to WP RewriteRule . /index.php [L] # # END wordpress
Add the exclusions previously discussed here in this thread as needed. Replace all broken pipe "¦" characters with solid pipes before use; Posting on this forum modifies the pipe characters. This is a total replacement for the code supplied with WP as bounded by the "Begin WP" and "End WP" comments, and fixes several performance-affecting problems. Notably, the unnecessary and potentially-problematic <IfModule> container is completely removed, and code is added and re-structured to both prevent completely-unnecessary file- and directory- exists checks and to reduce the number of necessary -exists checks to one-half the original count (due to the way mod_rewrite behaves recursively in .htaccess context). Joomla .htaccess code can benefit from an almost-identical modification. Jim
|
wheel

msg:4054595 | 5:04 pm on Jan 5, 2010 (gmt 0) | And in 2010, speed is important for Google ranking. I'm off to cut and paste - thanks Jim!
|
jdMorgan

msg:4054612 | 5:18 pm on Jan 5, 2010 (gmt 0) | Kind of important to prevent boring and losing your readers on some WP sites as well... :) Jim
|
johnnie

msg:4054989 | 9:01 am on Jan 6, 2010 (gmt 0) | | I'm off to cut and paste - thanks Jim! |
| Please, only copy and paste ;)
|
RonPK

msg:4055200 | 3:04 pm on Jan 6, 2010 (gmt 0) | Thanks for the code, jd. Perhaps add png to the static file formats: RewriteCond $1 \.(gif¦jpg¦png¦ico¦css¦js)$ [NC,OR]
|
jdMorgan

msg:4055256 | 4:22 pm on Jan 6, 2010 (gmt 0) | One could in theory exclude every single static resource on the site from this rule, and see tiny performance gains with [each of] even a fairly large number of such exclusions. But one can reach a point of diminishing returns by checking too many URL-paths or filetypes for exclusion. In addition, there's the maintenance problem of keeping up with a long and difficult-to-read list. So this shouldn't be an exhaustive list, but rather a list of the "high runners" as determined by number of accesses per unit time on any given site (check your stats). In that regard, every site will be different, and every site is likely to benefit from a slightly-different tweaking or tuning of this code snippet. Jim [edit] Clarified wording in first pp by adding words in brackets. [/edit] [edited by: jdMorgan at 7:14 pm (utc) on Jan. 6, 2010]
|
madmatt69

msg:4055321 | 5:26 pm on Jan 6, 2010 (gmt 0) | Wow this should be the default - Just enabled on my site, and there's a very noticable increase in load time. Maybe just coincidence, but I doubt it..Very cool.
|
ergophobe

msg:4055324 | 5:27 pm on Jan 6, 2010 (gmt 0) | Jim, I didn't want to bring it up in the other thread, because I didn't want to derail the discussion, but I was wondering the magnitude of the savings. A priori, I would guess this would be minor compare to, say, one plugin with a slow query. Obviously, the advantage here is that it will have the same results in all cases and you don't need to do benchmarking and profiling to find this slowdown. I'm guessing this is a single-digit millisecond thing, whereas a slow query can be a slowdown of a full second or more in the worst cases as wheel recently discovered with his WP issues. Any thoughts?
|
jdMorgan

msg:4055378 | 6:42 pm on Jan 6, 2010 (gmt 0) | File-exists and directory-exists checks are inefficient. In most cases, they will invoke several hundreds of lines of (machine) code at the OS file-handler level, and in some cases --especially on heavily-shared virtual servers-- the filesystem and ACLs may be only partially-cached due to excessive swapping. In that case, the OS is going to have to actually go read the physical disk, and compared to *any* code execution, that is going to be *very* slow. An important key to getting and staying rich is to not waste money. Similarly, an important key to avoid slowing down your site or being forced into an early server upgrade is to not waste CPU time. The out-of-the-box WP and Joomla rewrite code does four file- and directory-exists checks for each and every request to the server. IMHO, that's a waste of CPU time. I can't fix all of the badly-written WP plug-ins, but I can certainly try to correct the obviously-wasteful shortcomings in this code snippet. Just because I cannot do the former doesn't mean that I shouldn't bother with the latter. The best time to correct performance problems is at the outset. You won't have to fix problems tomorrow that you've already corrected today. I'm old-school -- from the days when 64kB was a *lot* of memory and CPU clock rates were measured in kilohertz. So I believe that it's easier to write tight fast code from the outset than to have to go find problems later and fix them. Note that I did not write the front-page "news" title about speeding up (all of) WordPress by a factor of two and I make no such claim. I posted above that this mod will speed up the WP .htaccess code by a factor of two (or better), which it does by avoiding the second-pass exists checks on index.php itself, and avoiding exists-checks on resources such as image files which obviously don't need to be handled by WP. Since image requests comprise over 50% of the requests on a typical site, I'm quite comfortable with that claim as I wrote it. I'd be happy to get some feedback here on any observable (or at least measurable) performance changes -- especially from busy sites with few plug-ins that are already experiencing slow page loads on heavily-shared virtual hosting where the server is "challenged" and such tweaks will make the most difference. Jim
|
ergophobe

msg:4055420 | 7:40 pm on Jan 6, 2010 (gmt 0) | | Note that I did not write the front-page "news" title about speeding up (all of) WordPress by a factor of two and I make no such claim. |
| Yes, I understood that and was reading your comments as intended. And I think these effects are more substantial than I expected. I always think of basic filesystem ops as fast compared to processing a lot of scripts or doing complex queries. I'll have a less cavalier attitude about that now.
|
mcglynn

msg:4055430 | 7:59 pm on Jan 6, 2010 (gmt 0) | Jim, is the speedup only applicable for .htaccess implementations of mod_rewrite? I use wordpress, but I have the mod_rewrite code in httpd.conf. I wrote a script that loops over 1 dynamic (wordpress-served) document and 5 static documents, and retrieves all of them many times, outputting the elapsed time for the whole set. I can detect no speedup at all due to the new mod_rewrite code. I've eliminated network latency as a factor, and I think I've controlled for Apache process forking too. In my tests, requests for wordpress-handled documents are significantly slower (more than 10x slower) than requests for static documents. This is true with either the new mod_rewrite code or the old. I'm happy to do more testing, if anyone has suggestions to try. Below is the domain-sanitized version of the code I'm using: RewriteEngine on RewriteCond %{HTTP_HOST} !^example\.org$ [NC] RewriteRule ^(.*)$ http://example.org/$1 [R=301,L] # Unless you have set a different RewriteBase preceding this point, # you may delete or comment-out the following RewriteBase directive # RewriteBase / # # if this request is for "/" or has already been rewritten to WP RewriteCond $1 ^(index\.php)?$ [OR] # or if request is for image, css, or js file RewriteCond $1 \.(gif¦jpg¦ico¦css¦js¦mp3¦wav¦pdf)$ [NC,OR] # or if URL resolves to existing file RewriteCond %{REQUEST_FILENAME} -f [OR] # or if URL resolves to existing directory RewriteCond %{REQUEST_FILENAME} -d # then skip the rewrite to WP RewriteRule ^(.*)$ - [S=1] # else rewrite the request to WP RewriteRule . /index.php [L] (My original code uses solid pipe characters to delineate the file extensions in the RewriteCond rule)
|
jdMorgan

msg:4055537 | 10:41 pm on Jan 6, 2010 (gmt 0) | > Jim, is the speedup only applicable for .htaccess implementations of mod_rewrite? Well, it's a matter of degree... You may not notice any change at all if your server isn't really struggling on -exists checks. You'll still get some (albeit small) speedup from preventing unnecessary -exists checks, but none from checking for "Not index.php" in the first RewriteCond. This is because unlike in a .htaccess context, only a single pass is made through mod_rewrite code in a server config context. There are a couple of tweaks you should do if this code is ported into the server config, depending on whether the code goes within a <Directory> container or not. Inside a <Directory> container in a server config file, you'd want:
# if this request is for any of these filetypes RewriteCond $1 \.gif$ [NC,OR] RewriteCond $1 \.jpg$ [NC,OR] RewriteCond $1 \.ico$ [NC,OR] RewriteCond $1 \.css$ [NC,OR] RewriteCond $1 \.js$ [NC,OR] RewriteCond $1 \.mp3$ [NC,OR] RewriteCond $1 \.wav$ [NC,OR] RewriteCond $1 \.pdf$ [NC,OR] # or if URL resolves to existing file RewriteCond %{REQUEST_FILENAME} -f [OR] # or if URL resolves to existing directory RewriteCond %{REQUEST_FILENAME} -d # then skip the rewrite to WP RewriteRule ^(.*)$ - [S=1] # else rewrite the request to WP RewriteRule . /index.php [L]
Whereas in a server config file but outside of any <Directory> container, you'd want:
# if this request is for any of theses filetypes RewriteCond $1 \.gif$ [NC,OR] RewriteCond $1 \.jpg$ [NC,OR] RewriteCond $1 \.ico$ [NC,OR] RewriteCond $1 \.css$ [NC,OR] RewriteCond $1 \.js$ [NC,OR] RewriteCond $1 \.mp3$ [NC,OR] RewriteCond $1 \.wav$ [NC,OR] RewriteCond $1 \.pdf$ [NC,OR] # or if URL resolves to existing file RewriteCond %{REQUEST_FILENAME} -f [OR] # or if URL resolves to existing directory RewriteCond %{REQUEST_FILENAME} -d # then skip the rewrite to WP RewriteRule ^/(.*)$ - [S=1] # else rewrite the request to WP RewriteRule ^/. /index.php [L]
These changes have to do with differences in performance of regex-ORs versus RewriteCond [OR]s* due to the fact that code in server config files is "pre-compiled" at server start-up as opposed to being interpreted on-the-fly in .htaccess, differences in the "local URL-path" as seen by the RewriteRule, and --as stated above-- the fact that mod_rewrite processing is not re-started from the top after any rule matches, as it is in .htaccess. In your situation, this code may not be much faster that the box-stock code provided by WP. But if you serve any images, media, or document files whatsoever, it will be faster nonetheless. Jim * Thanks again to Andreas Friedrich for benchmarking this difference several years ago. [edit] Ficksed speling errur. Removed BBcode [ bold ] tags from code.[/edit] [edited by: jdMorgan at 11:32 am (utc) on Aug 27, 2010]
|
g1smd

msg:4055554 | 11:03 pm on Jan 6, 2010 (gmt 0) | @jd -- title: comflicts => conflicts
|
freejung

msg:4055963 | 4:14 pm on Jan 7, 2010 (gmt 0) | This is brilliant, and reminds me why I read this board. The same improvement could be made to the default rewrite code for MODx, and probably for other CMS as well.
|
jdMorgan

msg:4056104 | 7:17 pm on Jan 7, 2010 (gmt 0) | Generalizing the approach so that it can be applied to other blog/forum/cart software, the key points are: In a .htaccess context, mod_rewrite rule processing is re-started after any RewriteRule is invoked. This re-starting continues to occur until a pass is made through all rules and no further rules match, and occurs whether or not [L] flags are used on the rules (An [L] flag causes the restart to occur immediately after the rule with the [L] flag matches, instead of allowing processing to continue to the last rule before restarting). Therefore, the target path of this RewriteRule should be excluded from this rule. This avoids doing unnecessary second-pass -exists checks on the path which has just been rewritten-to during the first pass. File- and directory-exists checks are very 'expensive' in terms of server resource utilization, and so should be deferred and/or avoided whenever possible. This can be done by doing the exists-checks last and by excluding the paths of resources which never need to be handled by the rewrite target (such as image, css, and js files in this case) and those which can always be presumed to exist (or which should result in a 404 or 410 response if they don't exist instead of being passed to the script for handling). Jim
|
spadilla

msg:4056106 | 7:19 pm on Jan 7, 2010 (gmt 0) | Applied this to two WP sites and they are smokin' fast now. Thanks!
|
miqrogroove

msg:4057387 | 5:28 pm on Jan 9, 2010 (gmt 0) | It should be noted that with RewriteCond $1 \.(gif¦jpg¦ico¦css¦js)$ [NC,OR] you will need to set up a non-WordPress 404 page. I've opened a ticket specifically about the internal re-re-writing of index.php at [core.trac.wordpress.org...]
|
jdMorgan

msg:4057467 | 8:05 pm on Jan 9, 2010 (gmt 0) | Apache's default 404 page will kick in if no custom 404 error page is declared. And that's OK, because since images, etc. are included objects within a page, rather than being linked "page-type" objects that are normally directly-requested, you don't really need a fancy or pretty 404 page for them. [added] The reason for this is that the browser will show a broken image, broken styling, or some other problem; It won't actually render the 404 'page' that it got with the object fetch error. [/added] Jim
|
vladowsky

msg:4090628 | 1:07 pm on Mar 3, 2010 (gmt 0) | I had similar problem with cpu usage on bluehost and tried to implement your solution however some minor issues occurred so I be grateful if someone help -how important is order of particular rules-i suppose very but I do not know if this order is right or maybe need to be rearranged. I also noticed that some plugins also add IF container so i removed them too.Did I do right? Thank you. This is copy of my .htaccess # BEGIN WordPress RewriteEngine On RewriteBase / RewriteCond $1 !^(cgi-bin|excludedDir2|file\.html) # if this request is for "/" or has already been rewritten to WP RewriteCond $1 ^(index\.php)?$ [OR] # or if request is for image, css, or js file RewriteCond $1 \.(gif|jpg|png|ico|css|js)$ [NC,OR] # or if URL resolves to existing file RewriteCond %{REQUEST_FILENAME} -f [OR] # or if URL resolves to existing directory RewriteCond %{REQUEST_FILENAME} -d # then skip the rewrite to WP RewriteRule ^(.*)$ - [S=1] # else rewrite the request to WP RewriteRule ^(.*)$ index.php?virtualpath=$1 [L,QSA] # END WordPress ###Begin HTTP Express <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} -f RewriteRule \.(jpeg|jpg|gif|bmp|png|swf|js|css)$ ./wp-content/plugins/http-express/do_http_header.php?file=%{REQUEST_FILENAME} [L] </IfModule> ###End HTTP Express #Turn ETagging off FileETag none #Turn ETagging on for MHTML-file <FilesMatch ".*booster_mhtml\.php$"> FileETag MTime Size </FilesMatch> #Force caching of some common files for some time in the browser's cache, to save bandwidth. #"Mod_expires" needs to be installed in your Apache server, to use this feature. <IfModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 minutes" ExpiresByType text/html "access plus 1 minutes" ExpiresByType text/css "access plus 1 months" ExpiresByType text/javascript "access plus 1 months" ExpiresByType text/plain "access plus 1 months" ExpiresByType application/x-javascript "access plus 1 months" ExpiresByType application/x-shockwave-flash "access plus 1 months" ExpiresByType image/gif "access plus 1 years" ExpiresByType image/jpeg "access plus 1 years" ExpiresByType image/jpg "access plus 1 years" ExpiresByType image/png "access plus 1 years" ExpiresByType image/x-icon "access plus 1 years" <FilesMatch ".*booster_mhtml\.php$"> ExpiresActive Off </FilesMatch> </IfModule> #Alternative caching using Apache's "mod_headers", if it's installed. #Caching of common files - ENABLED <IfModule mod_headers.c> <FilesMatch "\.(ico|pdf|js|css|gif|png|jpg|jpeg|ico|txt|html|htm)$"> Header set Cache-Control "max-age=2592000, public" </FilesMatch> #Remove comments, to disable video caching to the user's browser #<FilesMatch "\.(flv|wmv|avi|mpg|3gp|rm|mpeg|mp4|qt|mov|divx|xvid|wmv|asf|dat|xml)$"> #Header set Cache-Control "max-age=0, public" #</FilesMatch> </IfModule> #CSS-JS-Booster Start################################################# #Turn ETagging off FileETag none #Turn ETagging on for MHTML-file <FilesMatch ".*booster_mhtml\.php$"> FileETag MTime Size </FilesMatch> #Force caching of some common files for some time in the browser's cache, to save bandwidth. #"Mod_expires" needs to be installed in your Apache server, to use this feature. <IfModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 minutes" ExpiresByType text/html "access plus 1 minutes" ExpiresByType text/css "access plus 1 months" ExpiresByType text/javascript "access plus 1 months" ExpiresByType text/plain "access plus 1 months" ExpiresByType application/x-javascript "access plus 1 months" ExpiresByType application/x-shockwave-flash "access plus 1 months" ExpiresByType image/gif "access plus 1 years" ExpiresByType image/jpeg "access plus 1 years" ExpiresByType image/jpg "access plus 1 years" ExpiresByType image/png "access plus 1 years" ExpiresByType image/x-icon "access plus 1 years" <FilesMatch ".*booster_mhtml\.php$"> ExpiresActive Off </FilesMatch> </IfModule> #Alternative caching using Apache's "mod_headers", if it's installed. #Caching of common files - ENABLED <IfModule mod_headers.c> <FilesMatch "\.(ico|pdf|js|css|gif|png|jpg|jpeg|ico|txt|html|htm)$"> Header set Cache-Control "max-age=2592000, public" </FilesMatch> #Remove comments, to disable video caching to the user's browser #<FilesMatch "\.(flv|wmv|avi|mpg|3gp|rm|mpeg|mp4|qt|mov|divx|xvid|wmv|asf|dat|xml)$"> #Header set Cache-Control "max-age=0, public" #</FilesMatch> </IfModule> #CSS-JS-Booster End################################################# # BEGIN WPSuperCache <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / AddDefaultCharset UTF-8 RewriteCond %{REQUEST_URI} !^.*[^/]$ RewriteCond %{REQUEST_URI} !^.*//.*$ RewriteCond %{REQUEST_METHOD} !=POST RewriteCond %{QUERY_STRING} !.*=.* RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$ RewriteCond %{HTTP:Accept-Encoding} gzip RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L] RewriteCond %{REQUEST_URI} !^.*[^/]$ RewriteCond %{REQUEST_URI} !^.*//.*$ RewriteCond %{REQUEST_METHOD} !=POST RewriteCond %{QUERY_STRING} !.*=.* RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$ RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L] </IfModule> # END WPSuperCache
|
Dude_S

msg:4134348 | 11:25 pm on May 17, 2010 (gmt 0) | Just wanted to report my results after implementing Jim's changes: I tested a blog post with 7 in-post images, several background images in the design template and 1 CSS file. I ran it 10 times each before and after the change at [webpagetest.org...] set to "First View Only" (to eliminate caching effects). Average results: BEFORE - Time to first byte received: 0.870s - Time to start rendering: 1.815s - Total load time: 3.145s AFTER - Time to first byte received: 0.718s = -17.5% - Time to start rendering: 1.547s = -14.8% - Total load time: 2.908s = -7.5% Quite impressive! Thanks a lot!
|
g1smd

msg:4134560 | 8:24 am on May 18, 2010 (gmt 0) | @vladowsky: There's a lot of inefficiencies and syntax errors in that code. I'll get back to that when I have more time.
Dude_S: That's good to know! Thanks for the feedback.
|
vladowsky

msg:4134583 | 9:37 am on May 18, 2010 (gmt 0) | Thanks g1smd i really appreciate that, however i manage to clean this a bit so now it look like this: # Use PHP5CGI as default AddHandler fcgid-script .php ###Begin HTTP Express RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} -f RewriteRule \.(jpeg|jpg|gif|bmp|png|swf|js|css)$ ./wp-content/plugins/http-express/do_http_header.php?file=%{REQUEST_FILENAME} [L] ###End HTTP Express #CSS-JS-Booster Start################################################# #Turn ETagging off FileETag none #Turn ETagging on for MHTML-file <FilesMatch ".*booster_mhtml\.php$"> FileETag MTime Size </FilesMatch> #Force caching of some common files for some time in the browser's cache, to save bandwidth. #"Mod_expires" needs to be installed in your Apache server, to use this feature. <IfModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 minutes" ExpiresByType text/html "access plus 1 minutes" ExpiresByType text/css "access plus 1 months" ExpiresByType text/javascript "access plus 1 months" ExpiresByType text/plain "access plus 1 months" ExpiresByType application/x-javascript "access plus 1 months" ExpiresByType application/x-shockwave-flash "access plus 1 months" ExpiresByType image/gif "access plus 1 years" ExpiresByType image/jpeg "access plus 1 years" ExpiresByType image/jpg "access plus 1 years" ExpiresByType image/png "access plus 1 years" ExpiresByType image/x-icon "access plus 1 years" <FilesMatch ".*booster_mhtml\.php$"> ExpiresActive Off </FilesMatch> </IfModule> #Alternative caching using Apache's "mod_headers", if it's installed. #Caching of common files - ENABLED <IfModule mod_headers.c> <FilesMatch "\.(ico|pdf|js|css|gif|png|jpg|jpeg|ico|txt|html|htm)$"> Header set Cache-Control "max-age=2592000, public" </FilesMatch> #Remove comments, to disable video caching to the user's browser #<FilesMatch "\.(flv|wmv|avi|mpg|3gp|rm|mpeg|mp4|qt|mov|divx|xvid|wmv|asf|dat|xml)$"> #Header set Cache-Control "max-age=0, public" #</FilesMatch> </IfModule> #CSS-JS-Booster End################################################# # BEGIN WPSuperCache AddDefaultCharset UTF-8 RewriteCond %{REQUEST_URI} !^.*[^/]$ RewriteCond %{REQUEST_URI} !^.*//.*$ RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{QUERY_STRING} !.*=.* RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$ RewriteCond %{HTTP_USER_AGENT} !^.*(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).* RewriteCond %{HTTP:Accept-Encoding} gzip RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L] RewriteCond %{REQUEST_URI} !^.*[^/]$ RewriteCond %{REQUEST_URI} !^.*//.*$ RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{QUERY_STRING} !.*=.* RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$ RewriteCond %{HTTP_USER_AGENT} !^.*(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).* RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L] # END WPSuperCache # BEGIN WordPress RewriteCond $1 !^(cgi-bin|excludedDir2|file\.html) RewriteCond %{REQUEST_URI} !(^/index\.php|\.(gif|jpg|png|ico|css|js)|^/robots.txt|/sitemap\.xml)$ # if this request is for "/" or has already been rewritten to WP RewriteCond $1 ^(index\.php)?$ [OR] # or if request is for image, css, or js file RewriteCond $1 \.(gif|jpg|png|css|ico|js)$ [NC,OR] # or if URL resolves to existing file RewriteCond %{REQUEST_FILENAME} -f [OR] # or if URL resolves to existing directory RewriteCond %{REQUEST_FILENAME} -d # then skip the rewrite to WP RewriteRule ^(.*)$ - [S=1] # else rewrite the request to WP RewriteRule ^(.*)$ index.php?virtualpath=$1 [L,QSA] # END WordPress please tell me your suggestions
|
g1smd

msg:4134589 | 9:48 am on May 18, 2010 (gmt 0) | The main ones are missing escaping on various pattern characters, and overuse of very inefficient .* patterns when some other pattern will parse hundreds of times faster. There are others. You also need to put all your Redirect and Rewrite code together in one place, not spread about with other code in between. There's also no need for multiple ########, use just one.
|
vladowsky

msg:4134599 | 10:22 am on May 18, 2010 (gmt 0) | Thnx g1smd
|
nuwanda

msg:4198067 | 11:08 pm on Sep 7, 2010 (gmt 0) | Thanks for the code. Works well. Wondering if this is made redundant by WP caching plugins like Super Cache, etc.?
|
Dude_S

msg:4198260 | 7:17 am on Sep 8, 2010 (gmt 0) | No, as the two address completely different aspects of serving your site.
|
| This 37 message thread spans 2 pages: 37 ( [1] 2 ) > > |
|
|
|