.Htaccess Interview Questions


Prev Tutorial Next Tutorial

.Htaccess File Interview Questions

.htaccess interview questions

.Htaccess File Interview Question for Freshers

What is .Htaccess File ?

.htaccess files are configuration files of Apache Server which provide a way to make configuration changes on a per-directory basis.

.Why do we use this and Where?

Using this .htaccess& file, we can control php.ini and httpd.conf file

Why use .htaccess file

  • Define custom error pages
  • Banning certain IP addresses from accessing your site
  • redirecting users to other pages / sites
  • password protecting directories
  • enabling certain PHP modules
  • enabling SSI (server side includes)

How to define Custom Error Page using .htaccess file ?

.htaccess file for Custom Error Pages

ErrorDocument 404 /filenotfound.html

How to ban certain IP addresses from accessing your site using .htaccess ?


order allow,deny
deny from
deny from
allow from all

How to ban visitors accessing your site using .htaccess by Referrer ?


RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} otherdomain\.com [NC]
RewriteRule .* - [F]

How to redirect http to https ?


RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

How to redirect non-www to www ?


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

How to redirect all pages to newdomain ?


RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^olddomain\.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com [R=301,L]

What is meaning of R & L flag in htaccess ?

htacces R flag causes a HTTP redirect to be issued to the browser and 301 means its permanent redirect.

htaccess L fag causes to stop processing the rule set, if the rule matches, no further rules will be processed.

How to redirect to another directory within same domain ?


Redirect /olddir /newdir

what is meaning of 301, 302, 400, 401, 403, 404 and 500 error codes ?

  • 301 - Permanent movement
  • 302 - Temporary movement
  • 400 - Bad request
  • 401 - Authorization Required
  • 403 - Forbidden
  • 404 - Page Not Found
  • 500 - Internal Server Error

How does RewriteBase works in .htaccess ?

RewriteBase is used to set a base URL for your rewrites rules.


RewriteEngine On
RewriteBase /~new/

Do i need to restart the apache after chnages in .htaccess ?

No, no need to restart your server after change in .htaccess file.

What is htaccess F(forbidden) Flag ?

This flag causes the server to return a 403 Forbidden status code to the client. Se in below code If anyone trying to open any file with .exe, he will get Forbidden error.


RewriteRule \.exe - [F]

How to block few IP address ?


order allow,deny
deny from xxx.xxx.xxx.xxx #specify a specific address
allow from all

How to redirect to error/404.html when 404 errors comes?


ErrorDocument 400 error/404.html

How to set the php config variables in .htaccess ?


php_value upload_max_filesize 32M

htaccess NC(nocase) Flag ?

This flag causes RewriteRule to be matched in a case-insensitive manner.


RewriteRule ^(.*) /index.php?req=$1 [NC]

Prev Tutorial Next Tutorial


Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements

Buy Websites 9999595223
wifi cctv camera

Wifi CCTV Camera RS:1200 to 2499. Contact no. 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs