Forum Moderators: phranque

Message Too Old, No Replies

check on url rewrite code

making sure to not overload the server

         

dehumanizer

10:00 am on Mar 31, 2005 (gmt 0)

10+ Year Member



Greetings all!

I don't deal with Apache, then I ask orientation about the code below. I need to know if the code is done properly, since I heard many times that rewriting urls in the .htaccess can have big performance issues.

RewriteEngine on
Options +FollowSymlinks

RewriteBase /
RewriteRule ^products/([a-zA-Z0-9\]+)/([a-zA-Z0-9\+\ ]+)$ index.php?section=products&category=$1&title=$2 [L]
RewriteRule ^news/([a-zA-Z0-9\]+)$ index.php?section=news&newsid=$1 [L]
RewriteRule ^articles/([a-zA-Z0-9\]+)$ index.php?section=articles&articleid=$1 [L]

I appreciate any help.

Best regards,

- Michaelsen

sitz

11:41 am on Mar 31, 2005 (gmt 0)

10+ Year Member



Generally, the recommendation is to replace constructs like this:

([a-zA-Z0-9\]+)

with this:

([^/]+)

...as it's a bit more reliable. There *are* cases in which your version would be the way to go, but they're the exception rather than the rule.

As far as performance goes, the issue isn't so much one of the *nature* of your mod_rewrite rules in a .htaccess file, but simply the fact that they're there at all. More information about this is documented at [httpd.apache.org ], in the 'API Phases' section.

dehumanizer

12:50 pm on Mar 31, 2005 (gmt 0)

10+ Year Member



Hi sitz, thanks for the answer.

Looking at the API Phases I found something I'm not quite understanding.

"While URL manipulations in per-server context are really fast and efficient, per-directory rewrites are slow and inefficient due to this chicken and egg problem."

What does this exactly means? Maybe I'm doing something very bad.

Best regards,

- Michaelsen

jdMorgan

2:09 pm on Mar 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Maybe I'm doing something very bad.

No, not bad. Running code in .htaccess is comparatively slower than running the same code in httpd.conf, but unless you have a huge .htaccess file and a very busy site, it's no problem.

While it is good to be concerned about making things as efficient as possible, never forget that the computers are supposed to work for us, and not the other way around...

If you have a fairly busy site -- >10,000 unique impressions per day, then this may be cause for concern. Otherwise, the standard advice applies: Start with small .htaccess code, optiize it for efficiency, test it, and then evaluate the impact on your server's performance.

Just as a metric: I have a site where the main .htaccess file is 35kB in size. The site gets around 2,000 unique hits a day. I cannot measure any performance impact -- If there is an impact, it is buried in the time to process SSI, PERL scripts, PHP, and database lookups.

Jim

dehumanizer

8:52 pm on Mar 31, 2005 (gmt 0)

10+ Year Member



Ok Jim, now this is more clear for me.

This is a great forum.

Thank you!

- Michaelsen