.htaccess Snippets

Table of Contents Rewrite and Redirection Force www Force www in a Generic Way Force non-www Force non-www in a Generic Way Force HTTPS Force HTTPS Behind a Proxy Force Trailing Slash Remove Trailing Slash Remove Trailing Slash from Arbitrary Paths Redirect a Single Page Alias a Single Directory Alias Paths to Script Redirect an […]

Read More

Serve SVG with the Correct Content Type

If you are trying to use SVG like <img src=”image.svg”> or as a CSS background-image and the file is linked to correctly and everything seems right, but the browser isn’t displaying it, it might be because your server is serving it with an incorrect content-type. Add this to your .htaccess file at the root to […]

Read More

htaccess iPhone Detection

<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_USER_AGENT} .*iPhone.* RewriteRule ^index\.html$ http://www.mobile.mydomain.com [L] RewriteRule ^/$ http://www.mydomain.com/index.html [L] </IfModule>   This will redirect iPhone users to a URL you specify.

Read More

htaccess iPad Detection

Of course, the iPad is a pretty large screen and a fully capable browser, so most websites don’t need to have iPad specific versions of them. But if you need to, you can detect for it with .htaccess RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$ RewriteRule ^(.*)$ http://ipad.yourdomain.com [R=301] This will redirect iPad users to a URL you specify. […]

Read More

Denying and Allowing Access

Deny except from specific IPs Order deny,allow Deny from All Allow from xxx.xxx.xxx.xxx Allow from xxx.xxx.xxx.xxy Allow except from specific IPs Order deny,allow Allow from All Deny from xxx.xxx.xxx.xxx Deny from xxx.xxx.xxx.xxy Reference URL

Read More