Can the .htaccess file slow down a website to a crawl? If so, are there better ways to solve these problems with different rewrite rules and such?

Can the .htaccess file slow down a website to a crawl? If so, are there better ways to solve these problems with different rewrite rules and such? - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about php, htaccess, web-crawlers, , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


here is my htaccess file......



RewriteCond %REQUEST_URI  ^/patients/billing/FAQ_billing.html$ [OR]  
RewriteCond %REQUEST_URI ^/patients/billing/getintouch.html$
RewriteRule ^patients/billing/(.*).html$ $1.php [L,NC]

RewriteCond %REQUEST_URI ^/patients/findadoctor/a.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/b.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/c.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/d.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/e.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/f.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/g.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/h.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/i.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/j.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/k.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/l.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/m.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/n.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/o.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/p.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/q.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/r.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/s.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/t.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/u.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/v.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/w.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/x.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/y.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/z.html$
RewriteRule ^patients/findadoctor/(.*).html$ findadoctor.php?id=$1 [L,NC]


like that there is lots of rules around 250 line please help me...


Solution :

This is no doubt dependent on your remaining 200+ lines, but what you have posted so far would seem to be reducible to just 2 lines:



RewriteRule ^patients/billing/(FAQ_billing|getintouch).html$ $1.php [L,NC]
RewriteRule ^patients/findadoctor/([a-z]).html$ findadoctor.php?id=$1 [L,NC]


This shouldn't be reducing your site to a crawl.



As mentioned in comments, if you have something like the following, then it becomes difficult to reduce this further if you are only wanting to rewrite specific URLs.



RewriteCond %REQUEST_URI ^/patients/findadoctor/paediatriccardiacanaesthesiology.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/paediatriccardiovascularthoracicsurgery.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/bonemarrowtransplant.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/kidneytransplant.html$ [OR]
RewriteCond %REQUEST_URI ^/patients/findadoctor/cardiacanaesthesiology.html$
RewriteRule ^patients/findadoctor/(.*).html$ subcategorydoctor.php?id=$1 [L,NC]


However, if you can find a pattern, (eg. a-z and minimum 14 chars in length) then you could reduce this to something like:



RewriteRule ^patients/findadoctor/([a-z]14,).html$ subcategorydoctor.php?id=$1 [L,NC]


The htaccess does, by definition, slow down your site because the server must check every folder for the file - e.g. in your case the folders /patients/findadoctor/, /patients/ and the root folder. It is more efficient to write those rules in the server config itself, then set AllowOverride None, which will stop Apache looking for htaccess files. If you are using shared hosting you will unlikely be able to do this. Also it requires restarting the server every time you make a change to the config.



However, the performance in the majority of cases should not be a huge problem. First you should check that it is the htaccess file that's slowing down the site:




  • If the server responds immediately but the page takes a while to load, it would be a problem with the front end (HTML, CSS, Javascript). Check the Network tab in Chrome Dev Tools or Firebug, it will show timings.

  • If you temporarily remove all the htaccess rules and load the rewritten URL directly (e.g. findadoctor.php?id=a) and it still takes a long time to load, then it's a problem with the PHP code somewhere.


Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect