CSS-TricksHTAccess Snippets Feed | CSS-Tricks https://css-tricks.com Tips, Tricks, and Techniques on using Cascading Style Sheets. Thu, 23 May 2024 20:06:17 +0000 hourly 1 https://wordpress.org/?v=6.5.2 https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/07/star.png?fit=32%2C32&ssl=1 HTAccess Snippets Feed | CSS-Tricks https://css-tricks.com 32 32 45537868 Denying and Allowing Access https://css-tricks.com/snippets/htaccess/denying-allowing-access/ https://css-tricks.com/snippets/htaccess/denying-allowing-access/#comments Wed, 11 Feb 2015 18:50:06 +0000 Chris Coyier http://css-tricks.com/?page_id=195626 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
…]]>
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
]]>
https://css-tricks.com/snippets/htaccess/denying-allowing-access/feed/ 1 195626
Force HTTPS https://css-tricks.com/snippets/htaccess/force-https/ https://css-tricks.com/snippets/htaccess/force-https/#comments Wed, 11 Feb 2015 16:48:49 +0000 Chris Coyier http://css-tricks.com/?page_id=195624 RewriteEngine on RewriteCond %{HTTPS} !on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

If you have a proxy in front of your server performing TLS termination:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
…]]>
RewriteEngine on RewriteCond %{HTTPS} !on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

If you have a proxy in front of your server performing TLS termination:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
]]>
https://css-tricks.com/snippets/htaccess/force-https/feed/ 4 195624
Serve SVG with the Correct Content Type https://css-tricks.com/snippets/htaccess/serve-svg-correct-content-type/ https://css-tricks.com/snippets/htaccess/serve-svg-correct-content-type/#comments Sat, 22 Feb 2014 16:40:30 +0000 Chris Coyier http://css-tricks.com/?page_id=163734 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 …

]]>
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 fix it:

AddType image/svg+xml .svg .svgz
]]>
https://css-tricks.com/snippets/htaccess/serve-svg-correct-content-type/feed/ 18 163734
Append / Prepend Files https://css-tricks.com/snippets/htaccess/append-prepend-files/ https://css-tricks.com/snippets/htaccess/append-prepend-files/#comments Wed, 05 Oct 2011 12:26:04 +0000 Chris Coyier http://css-tricks.com/?page_id=14472 Rather than having to call / include a file you need on every single page, you can have them automatically prepended (top of file) or appended (bottom of file) automatically through your .htaccess file.

php_value auto_prepend_file "/real/path/to/file/functions.php"
php_value auto_append_file "/real/path/to/file/footer.php"
…]]>
Rather than having to call / include a file you need on every single page, you can have them automatically prepended (top of file) or appended (bottom of file) automatically through your .htaccess file.

php_value auto_prepend_file "/real/path/to/file/functions.php"
php_value auto_append_file "/real/path/to/file/footer.php"
]]>
https://css-tricks.com/snippets/htaccess/append-prepend-files/feed/ 7 14472
Subdirectories URL Internally Redirect to Query String https://css-tricks.com/snippets/htaccess/subdirectories-redirect-query-string/ https://css-tricks.com/snippets/htaccess/subdirectories-redirect-query-string/#comments Fri, 06 Aug 2010 03:17:13 +0000 Chris Coyier http://css-tricks.com/ The URL in the browser would be:

https://css-tricks.com/index.php/teachers/a/

The actual page rendered by the server would be:

https://css-tricks.com/index.php?search=teachers&sort=a

RewriteEngine on
RewriteRule ^index/([^/]+)/([^/]+).php /page.php?search=$1&sort=$2 [NC]
…]]>
The URL in the browser would be:

https://css-tricks.com/index.php/teachers/a/

The actual page rendered by the server would be:

https://css-tricks.com/index.php?search=teachers&sort=a

RewriteEngine on
RewriteRule ^index/([^/]+)/([^/]+).php /page.php?search=$1&sort=$2 [NC]
]]>
https://css-tricks.com/snippets/htaccess/subdirectories-redirect-query-string/feed/ 24 6987