Will RewriteRules In.htaccess affect site speed?

I plan to add no more than 10.htaccess to rewrite the URLs in the home directory, will this affect the execution (site load time) of my website?

my current .htaccess file

Options +FollowSymLinks RewriteEngine On RewriteRule ^([0-9]+)/([0-9]+)/([^.]+).html index.php?perma=$3 RewriteRule ^movies/([^.]+).html gallery.php?movie=$1 RewriteRule ^album/([^.]+).html gallery.php?album=$1 RewriteRule ^img/([^.]+)/([^.]+).html gallery.php?img=$2 RewriteRule ^movies.html gallery.php 
+4
source share
4 answers

Yes, this will affect boot time. The more rules / exceptions you have, the more time it takes to render. But: we are talking about micro / milliseconds that will not even be noticed by the human eye.

+1
source

You may need to see the effect of rewriting rule order performance when using apache mod_rewrite and, as @diolemo commented, over 20 rewriting rules this is not noticeable.

+1
source

Most of the time it takes to load a web page comes from extracting HTML, CSS, JavaScript and images. URL rewriting time is negligible.

Usually images are the biggest reason for slow loading times. A tool like Pingdom can help you in the perspective of loading various components in perspective.

http://tools.pingdom.com/fpt/

NTN.

+1
source

10 rules are not a problem, but for future reference. The usual approach is to redirect everything to one entry point and let the application route. A simple example:

.htaccess

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php [L,QSA] 

index.php

 $query = $_SERVER['REQUEST_URI']; $queryParts = explode('/', $query); switch($queryParts[0]) { case 'movies': // ... break; case 'album': // ... break; case 'img': // ... break; // ... default: // 404 not found } 

RewriteCond conditions guarantee that requests to existing files will not be overwritten. QSA is optional, it means "a query string has been added", so, for example, movies.html?sort=title rewritten to index.php?sort=title . The original request URI is available in $_SERVER['REQUEST_URI'] .

If your application is object-oriented, you will be interested in the Front Controller template. All major PHP frameworks use it in some way, this can help look at their implementation.

If not, a micro-wireframe like Silex could do the job for you. In Silex, your routing might look like this:

index.php

 require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); $app->get('/{year}/{month}/{slug}', function ($year, $month, $slug) use ($app) { return include 'article.php'; }); $app->get('/movies/{movie}.html', function ($movie) use ($app) { return include 'gallery.php'; }); $app->get('/album/{album}.html', function ($album) use ($app) { return include 'gallery.php'; }); $app->get('/img/{parent}/{img}.html', function ($parent, $img) use ($app) { return include 'gallery.php'; }); $app->get('/movies.html', function () use ($app) { return include 'gallery.php'; }); $app->run(); 

gallery.php and article.php should return their output. You can probably reuse existing scripts with this index.php if you replace $_GET['var'] with $var and add output buffering:

gallery.php

 ob_start(); // ... return ob_get_clean(); 
+1
source

All Articles