Server administration .htaccess

  • Thread starter Underground Forum
  • Start date
  • Tags

What is htaccess​

.htaccess - is an auxiliary configuration file of the Apache web server. All changes what made in .htaccess do not affect the global server's settings.
With .htaccess, you can control access to site files and directories, create links and redirects, remove duplicate pages from search, and much more.


“.” - just a point.
“*” - character or group of characters that can be present or absent an unlimited number of times.
“?” - character or group of characters that may or may not be present.
“+” - is usually placed before “*”.
“^” - the beginning of a new line.
"$" - the end of the line.
“$N” - number from 0 to 9. Used to refer to the RewriteRule template.
“%N”- number from 0 to 9. Used to refer to the RewriteCond template.
"[]" - square brackets, used for enumeration.
"{}" - curly braces.
“()” - used to highlight groups of characters.
“|” - an alternative choice.
"\" - a slash is needed to escape special characters.


SERVER_ADMINServer owner mailing address specified during installation.
SERVER_NAMEServer address, such as
SERVER_ADDRWeb server IP address.
SERVER_PORThttpd port.
SERVER_PROTOCOLVersion HTTP of server protocol.
SERVER_SOFTWAREName of the software running the web server.
HTTP_USER_AGENTInformation about the visitor's web browser.
HTTP_REFERERAddress of the first page.
HTTP_COOKIECOOKIEs that will be sent by the web browser.
HTTP_FORWARDEDAddress of the page the user came from.
HTTP_HOSTWeb server address, same as SERVER_NAME.
HTTP_ACCEPTCustomer's information.
SCRIPT_FILENAMEPath to a specific page or file.
PATH_INFOContains information about the end of the path.
QUERY_STRINGString passed as a request when working with CGI scripts.
AUTH_TYPEUsed to determine the type of client identification.
DOCUMENT_ROOTPath to the root directory of the web server.
REMOTE_HOSTAddress of the visitor.
REMOTE_IDENTInformation about the remote user.
REQUEST_METHODSpecifies the request type.


Redirect from http to https
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [QSA,R=301,L]

Simple, 301 redirect to another site:
Redirect 301 /

Redirecting the user to the technical page:
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^X.X.X.X$
RewriteCond %{REQUEST_URI} !^not-available.html
RewriteRule ^.*$ not-available.html


  • #2
Eu posso usar isso para proteger minha ferramenta de email para envio?