Start Exploring Keyword Ideas
Use Serpstat to find the best keywords for your website
The Ultimate Guide to .htaccess Files
What is .htaccess?
.htaccess are used by Apache-based web servers to make configuration changes for each directory. Generally, a file containing at least one configuration directive is placed in a specific document directory. Next, the directives are applied to that directory and subdirectories.
Developers typically encounter .htaccess files when using a Content Management System (CMS), such as WordPress or Magento. It is one of the files on your web server, which you can access via FTP, but it does not necessarily need to be edited before uploading. If you do change it, you must ensure that the filename remains '.htaccess' and doesn't end up with .html, .txt., or another extension.
To edit the file, go to the public_html directory and open it using File Manager in the cPanel. Alternatively, connect to your account via your preferred FTP Client.
Directives
Keep in mind that some web hosting services don't let you change the contents of the .htaccess file. However, in most cases, you should be able to create your .htaccess file or edit the one with your installed CMS. The .htaccess file is intended to give you control over a directory and all its contents.
You can use the .htaccess file to:
- Protect specific folders with a password
- Prevent directory listings
- Create and use personalized error pages
- Automatically redirect visitors to other pages
- Ban or allow users using IP addresses
- Change how files with specific extensions are utilized
How to use .htaccess
AuthName “Subscriber's Name”
AuthUserFile /path/to/password/file/.htpasswd
AuthType Basic
Require valid-user
ErrorDocument 401 /error_pages/401.html
AddHandler server-parsed.html
Using .htaccess file to create custom error pages for better SEO
The common error codes include:
- 400 – bad request
- 404 – file not found
- 403 – forbidden
- 401 – authorization required
- 500 – internal server error
Using .htaccess to deny users based on their IP address
Order allow,deny
Deny from 123.123.123.123
Deny from 255.255.43.
Allow from all
You can use different variations of IP addresses depending on what you want to block, including:
- Blocking a specific IP address
- Blocking a specific domain
- Blocking multiple IP addresses
- Blocking an entire subnet
- Blocking an IP based on CIDR
- Blocking IPv6 addresses
- Blocking IP based on regular expression
- Redirect based on IP address
- Block specific request types
- Complete notatio
You can also block all users except yourself (webmaster), by including the following lines in your .htaccess file:
Order allow, deny
Allow from 255.1.1.1
Deny from all
You can add as many 'allow from' and 'deny from' records as you want after the 'order allow, deny' line. Also, remember to change the bottom line, 'allow from all' or 'deny from all' depending on what you want.
Blocked users will be directed to the '403 Forbidden' error message, which you can amend to your liking.
Changing server signature
ServerSignature Email
SetEnv SERVER_ADMIN nospace@pleasenospace.com
ServerSignature Off
Final note
That said, you should remember that every edit implemented with a .htaccess file is also doable with httpd.conf file, but the converse is not true. You must enable .htaccess files in the httpd.conf file for it to be executable. Once enabled, they can be superior to certain settings, which gives you greater control over the features and functions you can manipulate.
Speed up your search marketing growth with Serpstat!
Keyword and backlink opportunities, competitors' online strategy, daily rankings and SEO-related issues.
A pack of tools for reducing your time on SEO tasks.
Discover More SEO Tools
Backlink Cheсker
Backlinks checking for any site. Increase the power of your backlink profile
API for SEO
Search big data and get results using SEO API
Competitor Website Analytics
Complete analysis of competitors' websites for SEO and PPC
Keyword Rank Checker
Google Keyword Rankings Checker - gain valuable insights into your website's search engine rankings
Recommended posts
Cases, life hacks, researches, and useful articles
Don’t you have time to follow the news? No worries! Our editor will choose articles that will definitely help you with your work. Join our cozy community :)
By clicking the button, you agree to our privacy policy.