Home » Php » php – Is having too many url rewrites in my htaccess a bad thing?

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

Posted by: admin July 12, 2020 Leave a comment

Questions:

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]
How to&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.

Answer:

Not really. If you have the ability to put them in the Apache configuration itself, they won’t have to be reloaded with every request.