.htaccess file or configuration file provide a way to make
configuration changes on a per-directory basis. A file that containing one or more
configuration directives, is placed in a particular document directory.
How to Create a .htaccess File?
Open any text editor application or notepad and file save as with .htaccess name. Enable mod_rewrite extension in php.ini file in Apache Web Server configurations if disabled.
RewriteEngine On it is turn on Rewrite Rules in Apache Server.
1 |
RewriteEngine on |
How to redirect from domain.com to www.domain.com ?
.htacces code for redirecting mydomain.com to www.mydomain.com
1 2 |
RewriteCond %{HTTP_HOST} ^mydomain.com RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L] |
How to make a seo friendly url using .htaccess ?
Static URLs are got much pretty ranking into Search Engines.
Search Engines are known to index the content of dynamic pages more slower than static pages.
http://phpmysqlquery.com/user.php?username=Avanish
to
http://phpmysqlquery.com/user/Avanish
1 2 |
RewriteRule ^user/([a-zA-Z0-9_-]+)$ user.php?username=$1 RewriteRule ^user/([a-zA-Z0-9_-]+)/$ user.php?username=$1 |