What is .htaccess? - Apache .htaccess Guide, Tutorials and Examples - Adzetech

.htaccess is a configuration file running the Apache Web Server program for use on web servers. The.htaccess file is detected and executed by the Apache Web Server software when a.htaccess file is placed in a directory that is in turn 'loaded via the Apache Web Server.'

These .htaccess files can be used to change the Apache Web Server software configuration to enable / disable additional features and functions to be provided by the Apache Web Server program. Such features provide simple redirect functionality, for example when an unfunded 404 file error occurs, or for more advanced functions such as password protection or hot link picture

Note: To open this file, please change your folder and file settings.htaccess file will be in hidden format.

What is .htaccess? - Apache .htaccess Guide, Tutorials and Examples - Adzetech

How to Create a .htaccess File?
Open and save any text editor program as with the.htaccess code, and allow mod rewrite extension in the php.ini file in the configurations of Apache Web Server.

Error Pages
Here error page is redirecting to error.html.

errorDocument 400 https://www.youwebsite.com/error.html
errorDocument 401 https://www.youwebsite.com/error.html
errorDocument 404 https://www.youwebsite.com/error.html
errorDocument 500 https://www.youwebsite.com/error.html

RewriteEngine On turns on Rewrite Rules in Apache Server. Change the value to off if you want to turn it off.

RewriteEngine on

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

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

Old Domain Redirection
htaccess code for redirect old domain(adzetech.com) to new domain(nepalitechnews.com). Live demo nnepalitechnews.com is now redirecting to adzetech.com

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

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

Friendly URLs
Friendly/Pretty URLs help in search engine rankings.

Profile URL
Profile parameter allows [a-zA-Z0-9_-] these inputs. More help read Understanding Regular Expression

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

Friends URL with Two Parameters
The first parameter here makes [ a-zA-Z0-9-] and the second parameter only allows the number [0-9]

RewriteRule ^profile/([a-zA-Z0-9_-]+)/([0-9]+)$ profile.php?username=$1&page=$2
RewriteRule ^profile/([a-zA-Z0-9_-]+)/([0-9]+)/$ profile.php?username=$1&page=$2

Hiding File Extension

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

Leave comment

Comments (1)


What are you searching for....?


Subscribe to us on youtube for updates of our videos first on youtube.


To receive updates on the latest news, tutorials and special offers, subscribe to our email newsletter today!


We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Privacy Policy That's Fine