Forum Moderators: phranque
Trying to bring across static url values to a dynamic script with variable $foo and $bar
I'm wondering which one is more efficient, and less on server load?
For example if given the url /request_uriA/long-text.html
Would it be better to
RewriteRule /request_uri([A-Z])/([\.]+)\.html some_script.php?foo=$1&bar=$2
OR..
RewriteRule /request_uri some_script.php
And do good ole regexp in some_script.php with parsing the $REQUEST_URI, str_posing the first alphabet after /request_uri, then retrieving long-text via preg-match
Average visits of 7000 daily let's say. with 1000 actual visit to some_script.php
scenario A have additional parse overhead of 7000 on a complicated URL, and scenario B have 7000 simple URL overhead, and 1000 script parse.
In this case...which one would be better, or am I over complicating things with miniscule comparisons?
Urbanzen
The interpreter for mod_rewrite is much smaller that that for PHP, and is also 'native' to the server, which means that the mod_rewrite method is a little faster and implies one less functional dependency. Therefore, there is no risk of losing URL-translation with the mod_rewrite method if, for example, you experience a problematic PHP upgrade. But on a modern server, I would not expect the server performance difference to be noticeable.
Also, if you are hosted on an Apache 2.x server, see the "AcceptPathInfo" directive, which can be used in place of mod_rewrite for your PHP-parsed method.
Jim
Of course, you may have gone through that already.
you can, via your .htaccess, send header telling the browser how long the downloaded files are to remain in the cache, so once downloaded it doesn't reload it, which contributes to lift your website charge
Apache .htaccess caching code
# 1 YEAR
<FilesMatch "\.(ico¦pdf¦flv)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
# 1 WEEK
<FilesMatch "\.(jpg¦jpeg¦png¦gif¦swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 2 DAYS
<FilesMatch "\.(xml¦txt¦css¦js)$">
Header set Cache-Control "max-age=172800, proxy-revalidate"
</FilesMatch>
# 1 MIN
<FilesMatch "\.(html¦htm¦php)$">
Header set Cache-Control "max-age=60, private, proxy-revalidate"
</FilesMatch>For fail-safe code implement this to the above
<IfModule mod_expires.c>
# any Expires Directives go here
</IfModule>
<IfModule mod_headers.c>
# any Header directives go here
</IfModule>
By using the <IfModule> containers, you turn off the code if the server does not support the required module. But the question is, "Do you really want to do that?" If you use <IfModule>, the server will continue to successfully accept requests, but it will not append the cache-control headers because that code section is disabled. Therefore, using the <IfModule> container leads to a silent failure!
I would rather have the server throw an error message if required modules are not installed.
For your site, you decide. :)
Also, take advantage of regular expressions to make your patterns more efficient:
<FilesMatch "\.([b]jpe?g[/b]¦png¦gif¦swf)$">
<FilesMatch "\.([b]html?[/b]¦php)$">
Jim