Embed presentation
Downloaded 24 times


![11/23/13 Htaccess File Tutorial and Tips.www.9lessons.info/2013/11/htaccess-file-tutorial-and-tips.html 3/4Domain Redirection.htacces code for redirecting yourwebsite.com to www.yourwebsite.comRewriteCond %{HTTP_HOST} ^yourwebsite.comRewriteRule (.*) http://www.yourwebsite.com/$1 [R=301,L]Sub Domain RedirectionSub domain redirection mapping to folder. Here http://www.yourwebsite.com is connectingto website_folder folder.RewriteCond %{HTTP_HOST} ^www.yourwebsite.com$RewriteCond %{REQUEST_URI} !^/website_folder/RewriteRule (.*) /website_folder/$1Here http://subdomain.yourwebsite.com is connecting to subdomain_folderfolder.RewriteCond %{HTTP_HOST} ^subdomain.yourwebsite.com$RewriteCond %{REQUEST_URI} !^/subdomain_folder/RewriteRule (.*) /subdomain_folder/$1Htaccess File Inside The Folder.Old Domain Redirectionhtaccess code for redirecting old domain(abc.com) to new domain(xyz.com). Livedemo fglogin.com is now redirecting to oauthlogin.comRewriteCond %{HTTP_HOST} ^abc.comRewriteRule (.*) http://www.xyz.com/$1 [R=301,L]RewriteCond %{HTTP_HOST} ^www.abc.comRewriteRule (.*) http://www.abc.com/$1 [R=301,L]Friendly URLsFriendly/Pretty URLs help in search engine rankings.Profile URLProfile parameter allows [a-zA-Z0-9_-] these inputs. More help read Understanding RegularExpressionhttp://labs.9lessons.info/profile.php?username=srinivastohttp://labs.9lessons.info/srinivasRewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fhtaccessfiletutorialandtips-140311011009-phpapp02%2f75%2fHtaccess-file-tutorial-and-tips-3-2048.jpg&f=jpg&w=240)
![11/23/13 Htaccess File Tutorial and Tips.www.9lessons.info/2013/11/htaccess-file-tutorial-and-tips.html 4/4RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?username=$1Messages URLhttp://labs.9lessons.info/messages.php?message_username=srinivastohttp://labs.9lessons.info/messages/srinivasRewriteRule ^messages/([a-zA-Z0-9_-]+)$ messages.php?message_username=$1RewriteRule ^messages/([a-zA-Z0-9_-]+)/$ messages.php?message_username=$1Friends URLhttp://labs.9lessons.info/friends.php?username=srinivastohttp://labs.9lessons.info/friends/srinivasRewriteRule ^friends/([a-zA-Z0-9_-]+)$ friends.php?username=$1RewriteRule ^friends/([a-zA-Z0-9_-]+)/$ friends.php?username=$1Friends URL with Two ParametersHere the first parameter allows [a-zA-Z0-9_-] and second parameter allows only number [0-9]http://labs.9lessons.info/friends.php?username=srinivas&page=2tohttp://labs.9lessons.info/friends/srinivas/2RewriteRule ^friends/([a-zA-Z0-9_-]+)/([0-9]+)$ friends.php?username=$1&page=$2RewriteRule ^friends/([a-zA-Z0-9_-]+)/([0-9]+)/$ friends.php?username=$1&page=$2Hiding File Extensionhttp://www.yourwebsite.com/index.htmltohttp://www.yourwebsite.com/indexRewriteRule ^([^/.]+)/?$ $1.html](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fhtaccessfiletutorialandtips-140311011009-phpapp02%2f75%2fHtaccess-file-tutorial-and-tips-4-2048.jpg&f=jpg&w=240)

This document provides a tutorial on how to create and configure .htaccess files to modify the behavior of an Apache web server. It explains how to create friendly URLs, redirect domains and subdomains, disable directory listings, configure error pages, and more. The document provides code examples for common tasks like redirection, rewriting URLs, and hiding file extensions.


![11/23/13 Htaccess File Tutorial and Tips.www.9lessons.info/2013/11/htaccess-file-tutorial-and-tips.html 3/4Domain Redirection.htacces code for redirecting yourwebsite.com to www.yourwebsite.comRewriteCond %{HTTP_HOST} ^yourwebsite.comRewriteRule (.*) http://www.yourwebsite.com/$1 [R=301,L]Sub Domain RedirectionSub domain redirection mapping to folder. Here http://www.yourwebsite.com is connectingto website_folder folder.RewriteCond %{HTTP_HOST} ^www.yourwebsite.com$RewriteCond %{REQUEST_URI} !^/website_folder/RewriteRule (.*) /website_folder/$1Here http://subdomain.yourwebsite.com is connecting to subdomain_folderfolder.RewriteCond %{HTTP_HOST} ^subdomain.yourwebsite.com$RewriteCond %{REQUEST_URI} !^/subdomain_folder/RewriteRule (.*) /subdomain_folder/$1Htaccess File Inside The Folder.Old Domain Redirectionhtaccess code for redirecting old domain(abc.com) to new domain(xyz.com). Livedemo fglogin.com is now redirecting to oauthlogin.comRewriteCond %{HTTP_HOST} ^abc.comRewriteRule (.*) http://www.xyz.com/$1 [R=301,L]RewriteCond %{HTTP_HOST} ^www.abc.comRewriteRule (.*) http://www.abc.com/$1 [R=301,L]Friendly URLsFriendly/Pretty URLs help in search engine rankings.Profile URLProfile parameter allows [a-zA-Z0-9_-] these inputs. More help read Understanding RegularExpressionhttp://labs.9lessons.info/profile.php?username=srinivastohttp://labs.9lessons.info/srinivasRewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fhtaccessfiletutorialandtips-140311011009-phpapp02%2f75%2fHtaccess-file-tutorial-and-tips-3-2048.jpg&f=jpg&w=240)
![11/23/13 Htaccess File Tutorial and Tips.www.9lessons.info/2013/11/htaccess-file-tutorial-and-tips.html 4/4RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?username=$1Messages URLhttp://labs.9lessons.info/messages.php?message_username=srinivastohttp://labs.9lessons.info/messages/srinivasRewriteRule ^messages/([a-zA-Z0-9_-]+)$ messages.php?message_username=$1RewriteRule ^messages/([a-zA-Z0-9_-]+)/$ messages.php?message_username=$1Friends URLhttp://labs.9lessons.info/friends.php?username=srinivastohttp://labs.9lessons.info/friends/srinivasRewriteRule ^friends/([a-zA-Z0-9_-]+)$ friends.php?username=$1RewriteRule ^friends/([a-zA-Z0-9_-]+)/$ friends.php?username=$1Friends URL with Two ParametersHere the first parameter allows [a-zA-Z0-9_-] and second parameter allows only number [0-9]http://labs.9lessons.info/friends.php?username=srinivas&page=2tohttp://labs.9lessons.info/friends/srinivas/2RewriteRule ^friends/([a-zA-Z0-9_-]+)/([0-9]+)$ friends.php?username=$1&page=$2RewriteRule ^friends/([a-zA-Z0-9_-]+)/([0-9]+)/$ friends.php?username=$1&page=$2Hiding File Extensionhttp://www.yourwebsite.com/index.htmltohttp://www.yourwebsite.com/indexRewriteRule ^([^/.]+)/?$ $1.html](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fhtaccessfiletutorialandtips-140311011009-phpapp02%2f75%2fHtaccess-file-tutorial-and-tips-4-2048.jpg&f=jpg&w=240)