Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is having too many url rewrites in my htaccess a bad thing?

I am new to url rewriting. My htaccess file has about 20 rewrites so far and more to come. I am curious if the more I have, will it slow my page load or anything of the sort?

I am trying my best to structure my urls so I can have minimal rewrites but I am not sure if I have already failed by having 20 already.

RewriteRule ^account/(\w+)(.*)$ ./index.php?option=account&task=$1 [L,PT]

# Auth Controller
RewriteRule ^auth/(\w+)(.*)$ ./index.php?option=auth&task=$1 [L,PT]

# Collections Controller
RewriteRule ^collections(.*)$ ./index.php?option=collections [L,PT]
RewriteRule ^collections/(\w+)(.*)$ ./index.php?option=collections&task=$1 [L,PT]

# Friends Controller
RewriteRule ^friends/(\w+)(.*)$ ./index.php?option=friends&task=$1&%{QUERY_STRING} [L,PT]

# Index Controller
RewriteRule ^index(.?)$ ./index.php?%{QUERY_STRING} [L,PT]
RewriteRule ^index/index(.?)$ ./index.php?%{QUERY_STRING} [L,PT]
RewriteRule ^about(.*)$ ./index.php?option=index&task=about [L,PT]
RewriteRule ^ideas(.*)$ ./index.php?option=index&task=ideas [L,PT]
RewriteRule ^contact(.*)$ ./index.php?option=index&task=contact [L,PT]
RewriteRule ^faq(.*)$ ./index.php?option=index&task=faq [L,PT]

# Messages Controller
#RewriteRule ^messages/(\d+)(.*)$ ./index.php?option=messages&account_id=$1 [L,PT]

# Run Controller
RewriteRule ^run/(\d+)(.*)$ ./index.php?option=run&account_id=$1 [L,PT]

# Stores Controller
RewriteRule ^stores/(\w+)(.?)$ ./index.php?option=stores&task=$1 [L,PT]
like image 627
Justin Carlson Avatar asked Oct 21 '11 23:10

Justin Carlson


1 Answers

Technically .htaccess does slow down Apache but in reality the performance penalty is minuscule. Do not worry about having too many rewrites simply because of performance issues.

Further reading: https://webmasters.stackexchange.com/questions/21055/alternative-to-htaccess-due-to-bad-performance

But as Brad said, 20 rewrites sounds like a lot. I would condense them simply for readability purposes because it can get difficult to debug which rule does what when you have 20 rules on top of each other.

like image 158
TheLQ Avatar answered Nov 12 '22 22:11

TheLQ