Академический Документы
Профессиональный Документы
Культура Документы
In this article, I am going to discuss htaccess tips and tricks. I am talking about URL rewriting tips, htaccess SEO optimization, .htaccess security tips, .htaccess deny
access to directory, .htaccess deny directory listing etc. .htaccess is most important for a website. before starting .htaccess tips and tricks we should know about
.htaccess first.
what is .htaccess?
.htaccess is a server configuration file which is use for Apache Web Server software. when a .htaccess place in a web directory then this .htaccess file loaded via
Apache Web Server and follow .htaccess instructions. Apache web server works which command use on .htaccess file. .htaccess files provide a way to change web
server configurations.
Or .htaccess file is now ready we are in the way of various .htaccess tricks and tips.
Custom Directory Index Files
DirectoryIndex index.php index.html index.htm
You can change your directory index and set custom directort index file using this htaccess code. If you use DirectoryIndex index.php code in .htaccess file then server
run index.php file as default web page. You can set your custom file as you want.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteEngine on
RewriteRule ^user/([A-Za-z0-9-_+]+)/?$ user.php?name=$1 [NC,L]
Make a profile page www.example.com/user.php?name=username to www.example.com/user/username
RewriteEngine on
RewriteRule ^user/([a-zA-Z0-9_-]+)/([0-9]+)$ user.php?id=$2
<Files php.ini>
Order Allow,Deny
Deny from all
</Files>
<Files .htaccess>
Order Allow,Deny
Deny from all
</Files>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access 1 month"
</IfModule>
<ifModule mod_headers.c>
<filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</filesMatch>
</ifModule>
Options +FollowSymlinks
ServerSignature Off
# Rule #4a - Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
# Rule #4b - Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
# Rule #4c - Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|[|%[0-9A-Z]{0,2}) [OR]
# Rule #4d - Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|[|%[0-9A-Z]{0,2})
# Rule #4e - Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
These are some htaccess tricks and tips. There are a lot of htaccess tutorials. Follow these and make your website more secure, SEO Friendly and make your website
as your own style. If you have any question or comment about this htaccess tips and tricks please don't hesitate to do that, please comment your question in comment
section.
Recommended For You
Image watermark in PHP
Age Calculator In PHP
Send mail in PHP
Word Count In PHP
Top Posts
Random code generator in PHP
Get user real IP address in PHP
Get location using IP address in PHP
Create hex to rgba converter tool
Image watermark in PHP
Get random image from directory in PHP
Get country name from country code in PHP
PHP Date Function Tutorial
Online QR Code Generator In PHP
Dynamic Multi-Color Menu
© phpans.com 2015-16