How to Enable .htaccess in Xampp Application

LoadModule rewrite_module modules/mod_rewrite.so

How to Create a .htaccess File?

Open any text editor application and file save as with .htaccess in root directory folder. Check the below screenshot for more reference.

Default directory Listing



Disable directory Listing

If you want to disable folder files listing, include following code in .htaccess file.

# Disable Directory Browsing Options All -Indexes

Error Pages Redirection

error.html

errorDocument 400 http://localhost/skptricks/demo/error.html errorDocument 401 http://localhost/skptricks/demo/error.html errorDocument 404 http://localhost/skptricks/demo/error.html errorDocument 500 http://localhost/skptricks/demo/error.html

error.html

NOTE :





Example :

RewriteEngine on

RewriteEngine off





You need to turn on the RewriteEngine for the below examples, Otherwise it will not work.

Domain Redirection .htacces code for redirecting yourwebsite.com to www.yourwebsite.com





RewriteCond %{HTTP_HOST} ^ yourwebsite.com RewriteRule (.*) http://www.yourwebsite.com /$1 [R=301,L]

Sub Domain Redirection Sub domain redirection mapping to folder. Here http://www.yourwebsite.com is connecting to website_folder folder.



RewriteCond %{HTTP_HOST} ^ www\.yourwebsite\.com $ RewriteCond %{REQUEST_URI} !^/ website_folder / RewriteRule (.*) / website_folder /$1

Similarly we can link to sub-domain folder.

Here http://subdomain.yourwebsite.com is connecting to subdomain_folder folder.



RewriteCond %{HTTP_HOST} ^ subdomain\.yourwebsite\.com $ RewriteCond %{REQUEST_URI} !^/ subdomain_folder / RewriteRule (.*) / subdomain_folder /$1 Profile URL Profile parameter allows [a-zA-Z0-9_-] these inputs and here we have used regular expression statement. we are apply rewrite rules to below URL.

http://localhost/skptricks/demo/profile.php?username=skptricks

to

http://localhost/skptricks/demo/skptricks



RewriteEngine on RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1 RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?username=$1



Post URL Similarly we are using rewrite rules in another URL. Which will rewrite the URL in below format.

http://localhost/skptricks/demo/post.php?title=html

to

http://localhost/skptricks/demo/post/html





RewriteEngine on RewriteRule ^post/([a-zA-Z0-9_-]+)$ post.php?title=$1 RewriteRule ^post/([a-zA-Z0-9_-]+)/$ post.php?title=$1 .htacces code for redirectingtoSub domain redirection mapping to folder. Hereis connecting tofolder.Similarly we can link to sub-domain folder.Hereis connecting to_folder folder.we are apply rewrite rules to below URL.Similarly we are using rewrite rules in another URL. Which will rewrite the URL in below format.





Forum URL With Two Parameter

RewriteEngine on RewriteRule ^forum/([0-9]+)/([a-zA-Z0-9_-]+)$ forum.php?year=$1&title=$2 RewriteRule ^forum/([0-9]+)/([a-zA-Z0-9_-]+)$ forum.php?year=$1&title=$2

Hiding File Extension

RewriteRule ^([^/.]+)/?$ $1.php



Video Link :





Download Link : https://github.com/skptricks/php-Tutorials/tree/master/Htaccess%20File%20Tutorial%20and%20Tips



Do Comments in case of any questions... Do Comments in case of any questions...

Today we are going to share some ideas aboutBasically Htaccess is a configuration file use on web servers running the Apache Web Server softwareand Usingyou can easily configure and redirect Apache Web Server file system..htaccess is a configuration file for use on web servers running the Apache Web Server software. When a .htaccess file is placed in a directory which is in turn 'loaded via the Apache Web Server', then the .htaccess file is detected and executed by the Apache Web Server software. These .htaccess files can be used to alter the configuration of the Apache Web Server software to enable/disable additional functionality and features that the Apache Web Server software has to offer. These facilities include basic redirect functionality, for instance if a 404 file not found error occurs, or for more advanced functions such as content password protection or image hot link prevention.Once you have installed Xampp application in your system, all the configuration file should be available with you in your system. Here we have installed Xampp application in D: Drive.Lets follow the below steps to enable the .htaccess :1. Open the below directory in you system :2. Then OpenFile using text editor and search for below line :and Remove hash form the that line and save that file after that restart your Apache server and reload that page in browser.Lets see the few basic operations forconfiguration file.This is the default directory listing for Xampp application, no restriction is here.If you enter invalid Link, then it will redirect topage. For Error Page redirection, you require following code :To use Rewrite Rules feature in Apache Server, you need to turn on the RewriteEngine. if you want to turn off, just change the value to off. Mention the below statement in .htaccess file.Similarly we are using rewrite rules in another URL. Which will rewrite the URL in below format.If you want to hide the webpage extension then use the below code :