Archive for the ‘Apache’ tag
Speed up and save traffic with Apache and mod_deflate
One of our sites was loading pretty slow. This is mostly caused by a very heavy design. But i still wanted to speed things up a bit.
The first step was compressing all JavaScript files with the Yahoo YUI compressor. The next step was to activate mod_deflate and compress all text, XML, and media files (JavaScript, CSS).
When the mod_deflate module is loaded in apache this is a pretty easy thing to do. Just add the following lines to a .htaccess file in the root of the web site / application.
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
The first line enables mod_deflate for the specified extensions. And the other three lines are there because of the way some older browsers handle gzipped data.
To test if the the content is transmitted over the line in gzipped format i used the Live HTTP Header Firefox extensions. This let’s you watch the Live HTTP headers as the fly by.
Check the HTTP/ 1.x 200 OK response from the webserver for the following line
Content-Encoding: gzip
And to test what happens if a browser doesn’t support gzipped data. You can set a configuration parameter in Firefox about:config.
gzip, deflate enabled:
network.http.accept-encoding = gzip,deflate
gzip, deflate disabled:
network.http.accept-encoding =
References :
http://www.howtoforge.com/apache2_mod_deflate
301 Redirect losing POST data
Earlier this week i implemented the forcing of trailing slashes for some websites. And this worked out great.
But today one of the ladies here at the office noticed the contact form on one site wasn’t functioning properly anymore.
So i did some debugging and quickly came to the conclusion the POST data array was empty after a submit of the form. That’s weird i thought. And didn’t really have a clue where to start looking. The code wasn’t touched for a couple of weeks. Bu then i remembered adding the forcing of the trailing slash.
So i browsed to the contact form and did a view source. And there was the problem. The form submitted to
/contact/verstuurd
A URL without a trailing slash. This causes apache to rewrite the url to
/contact/verstuurd/
And this also seems to turn the POST into a GET request.
So to fix it just changed to URL in the form to reflect the correct end point. But i have to say i didn’t expect this to happen. I understand why it happens. And it’s pretty logical. But i wonder if there’s a way around this behavior?
Forcing a trailing slash with mod_rewrite
I’m doing some SEO optimization for a couple of websites. And one of the small steps is to force a trailing slash on all URL’s that do not point to a file on the server. The reason I’m doing this is to go around the duplicate content problem.
/trip/80
/trip/80/
Both point to the same content. But a crawler would see this as two different URL’s. Which off course is correct. But this can lead to duplicate content being indexed in search engines. Which could result in penalties for the site in question. So to fix this problem we add three simple lines to the main .htaccess file
# If a requested file does not exists
RewriteCond %{REQUEST_FILENAME} !-f# If a requested directory does not exist
RewriteCond %{REQUEST_FILENAME} !-d# Force a trailing slash to the request
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]






