YaBB - Yet another Bulletin Board

Welcome, Guest. Please Login or Register

  Home English Norsk HelpLoginRegisterSearch  
 
 
Pages: 1 2 3 
Send Topic Print
HTML5 - Hypertext Markup Language (Read 126075 times)
Reply #30 - 06/24/18 at 21:57:37  

Administrator   Offline
YaBB Administrator
Welcome to My Bulletin
Board
Oslo

Gender: male
Posts: 267
*****
.htaccess


Apache .htaccess is a configuration file that adjusts the settings of the web servers. The file gets immediate effect in all the files and subfolders of the specified folder it is loaded to and is useful when you do not have access to the configuration file in the main server. An example of a .htaccess file is to redirect from www to non-www and vice versa, as well as from HTTP to HTTPS:

Code:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
 



The example is from Simone's Blog (Carletti, 2016). The first line starts Apache's runtime rewriting engine. The next two lines are the redirect conditions. The first condition determines whether the request uses a non-HTTPS URL, while the other determines whether the request uses www URL. The fourth line avoids directing the host name directly to the URL. «RewriteRule» is the heart of the redirect, and tells Apache to redirect any request to a new URL. The flag «L» stops processing other rules and redirects immediately. «NE» asks Apache not to escape special characters. «R = 301» uses HTTP status code 301. If you want to redirect non-www to www, you can change the third and the fifth lines:

Code:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
 




Sources
 
 
IP Logged
 
Pages: 1 2 3 
Send Topic Print