5

I am planning on redirecting about 100 using (301 .htaccess) and was wondering if this will slow down the performance or have any effect since the file will get heavy ?

Are there any types of entries in .htaccess that affect performance more than others ?

Example:

redirect 301 /old page.shtml http://www.example.com/newdir/newpage.shtml

Dony
  • 212
  • 1
  • 8
  • Might be helpful if you show how you would do the redirect. `RedirectMatch` or `RewriteRule` – Gerben Feb 25 '12 at 18:56
  • Dony, you should mention in your Q that you are running on a VPS as this extends the solution options :-) – TerryE Feb 25 '12 at 23:24

1 Answers1

4

If you can, you may move your .htaccess directives into the VHost file.

Using the VHost will be faster because apache will not read the .htaccess everytime a page is loaded, the VHost will be executed when apache loads.


(Reference: Move .htaccess content into vhost, for performance)

Community
  • 1
  • 1
  • how will moving .htaccess directives into the VHost file affect my other sites that I have. Will my other sites read this .htaccess too ? – Dony Feb 25 '12 at 19:11
  • yes they will, unless you disable `mod_rewrite`, which you should not. every site has it's own VHost (if not wildcard), therefore you can have your rules in VHost for a site, and keep them in `.htaccess` for the other sites. –  Feb 25 '12 at 20:00
  • Is there a rule to bulk instead of doing it one-by-one ? For example Im redirecting only pages with (.shtml extension) to a sub-directory ( /b/page.shtml ) from the root dir. – Dony Feb 25 '12 at 20:35
  • 1
    `RewriteRule ^(.*)\.shtml$ /b/$1.shtml [R=301,L]` –  Feb 25 '12 at 20:45
  • The rule adds an extra /b/ when it redirects ( http://www.example.com/b/b/page.shtml ) and should be http://www.example.com/b/page.shtml – Dony Feb 25 '12 at 20:51
  • what's your `RewriteBase`? try `RewriteRule ^/(.*)\.shtml$ /b/$1.shtml [R=301,L]` will redirect example.com/page.shtml to /b/page.shtml –  Feb 25 '12 at 20:57
  • this is what other rules I have there : RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA] – Dony Feb 25 '12 at 21:03
  • @Dony, if there is a grammar to your replacements then you should read up on using [regexps in the rewrite engine](http://httpd.apache.org/docs/current/rewrite/intro.html) and also consider using a RewriteMap in your vhost file – TerryE Feb 25 '12 at 23:20
  • Also your pattern `^([^?]*)` works but is bizarre. `[^?]*` means a repeat of not ?, but since you will never see a ? in a rule pattern, this is just the same as `.*` – TerryE Feb 25 '12 at 23:23
  • @develroot, the quote is incorrect. The vhost file is physically read and cached at Apache load, but the vhost rules are themselves scanned once per internal redirect. What is different is that sucessful rules in a none per-directory context do not themselves, See [(ref)](http://httpd.apache.org/docs/current/rewrite/tech.html), plus look at any relevant rewrite.log – TerryE Feb 25 '12 at 23:31