For lattest updates please visit, http://web2students.com/web2blog/
.htaccess (hypertext access) file has only extension no name. So,if you can't create on windows, just download from internet and edit it. As there is no file name, it's sometimes invisible. So, on server, first change settings to view hidden files (if you have permission and ftp/ cpanel has this feature). It's directory-level configuration file supported by several web servers. Directory-level configuration means, it will effect files that are in that directory or in sub-directory, it can't effect outside that directory.
What we can do with .htaccess?
# this is comment
404 error- Following file will be loaded when 404 error will occur,
Above line says to redirect from /folder/oldfile.html to /newpage.html . [L,R=301] , This means, if this match is found, it's last command. Server don't try to match rest of .htaccess file. And R=301 means to re-direct and sending 301 headers. There are 2 types of headers for re-direct. 301 and 302. 301 is used for,Moved Permanently response and 302 is used for Moved temprory response. Why we care about these headers?It's used by search engine. If document is moved permanent , search engine will update the url in it's database. Else, it will not update.
You need to read all with example to understand below,
RewriteCond %{REQUEST_FILENAME} !-f
Explanation - Above line has 2 parts. First, RewriteCond (re-write condition)- this is re-write continue directives. It tells if condition is met, then continue re-writing. Condition is %{REQUEST_FILENAME} !-f. it says, if requested file is not found !-f means if file is not found then apply re-write rule (that rule will be written below that)
RewriteCond %{REQUEST_FILENAME} !-d
Above tells, if directory is not found then continue re-writing.
Now, if you want to re-write like,
.htaccess (hypertext access) file has only extension no name. So,if you can't create on windows, just download from internet and edit it. As there is no file name, it's sometimes invisible. So, on server, first change settings to view hidden files (if you have permission and ftp/ cpanel has this feature). It's directory-level configuration file supported by several web servers. Directory-level configuration means, it will effect files that are in that directory or in sub-directory, it can't effect outside that directory.
What we can do with .htaccess?
- URL- rewrite - (like user visits, http://web2students.blogspot.in/file1.html but really access, public_html/file2.html ). It is used for SEO purpose.
- Error document (404 page) - we can re-direct to customized page when user visits, non existing page.
- Blocking user by IP address.
- Many more things.
# this is comment
404 error- Following file will be loaded when 404 error will occur,
ErrorDocument 404 /error_handler.html
We can also handle other errors, ( 400, 401, 500, etc).
Blocking IP address,
order allow,deny
deny from 11.11.1.1
deny from 22.22.2.2
allow from all
Explanation -
allow and deny are directives. Directives means one line command. First we write that following section defines allowing or denying access to server by using line,
order allow,deny
then we write deny from ip address (it's used to deny access to that ip address).
Last line used to allow all other.
Redirecting to other page,
redirect /folder/oldfile.html /newpage.html [L,R=301]Above line says to redirect from /folder/oldfile.html to /newpage.html . [L,R=301] , This means, if this match is found, it's last command. Server don't try to match rest of .htaccess file. And R=301 means to re-direct and sending 301 headers. There are 2 types of headers for re-direct. 301 and 302. 301 is used for,Moved Permanently response and 302 is used for Moved temprory response. Why we care about these headers?It's used by search engine. If document is moved permanent , search engine will update the url in it's database. Else, it will not update.
You need to read all with example to understand below,
RewriteCond %{REQUEST_FILENAME} !-f
Explanation - Above line has 2 parts. First, RewriteCond (re-write condition)- this is re-write continue directives. It tells if condition is met, then continue re-writing. Condition is %{REQUEST_FILENAME} !-f. it says, if requested file is not found !-f means if file is not found then apply re-write rule (that rule will be written below that)
RewriteCond %{REQUEST_FILENAME} !-d
Above tells, if directory is not found then continue re-writing.
Now, if you want to re-write like,
http://shoppingsite/product.php?product_id=1 to http://shoppingsite/products/productnameYou will get productname from database. There is 1 to 1 relation of product_id and productname. Else it will not run. Why change to such URL?First it's good to have url having name of product not id. Second, good for SEO. Third, easy to remember. More coming soon. Also read this, http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
No comments:
Post a Comment