.htaccess mod_rewrite for production server
This will allow you to ‘hide’ file extensions and make your site URL(s) much more friendly for search engines.
For example, instead of:
http://www.mydomain.com/products.php?name=dvdplayer
you can present
http://www.mydomain.com/products/dvdplayer
Additionally, you can customize error pages specific to the error itself to give your users/customers a more customized feel if they experience an error. And with some additional code, you can even generate some complex logging to track how/when that user encountered that error.
#Redirect errors to more specific pages
ErrorDocument 404 /404error.php
ErrorDocument 500 /500error.php
#SEO query strings
RewriteEngine on
RewriteRule ^about/?$ /about.php [L]
RewriteRule ^products/?$ /products.php [L]
RewriteRule ^products/([a-z]+)/?$ /products.php?name=$1 [L]
RewriteCond %{HTTP_HOST} !^www.mydomain.com$
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.mydomain.com/ [R=301,L]
Leave a Reply