2
988

The files .htaccess and index.php

The file .htaccess at the root of the website configures a single entry point in the code for all requests: index.php. It also redirects all requests to the full www. domain name of the website, if necessary. It can be edited to force a dialogue in HTTPS. NOTE: The file .htaccess is generated when the site is created.

.htaccess
  1. SetEnv PHP_VER 8
  2.  
  3. Options -Indexes
  4. Options +FollowSymLinks
  5.  
  6. ErrorDocument 403 /index.php
  7. ErrorDocument 404 /index.php

Line 1 tells Apache which version of PHP must be used to run the code of the website. iZend is validated with PHP 8.4 but still works with PHP 5.3.

Line 3 forbids the generation by Apache of the listing of a directory content. Line 4 allows following symbolic links.

Lines 6 and 7 redirect access and addressing errors to index.php.

  1. RewriteEngine On
  2.  
  3. RewriteCond %{HTTPS} off
  4. RewriteCond %{HTTP_HOST} ^sitename\.net [NC]
  5. RewriteRule ^(.*)$ http://www.sitename.net/$1 [R=301,L]
  6.  
  7. RewriteCond %{HTTPS} on
  8. RewriteCond %{HTTP_HOST} ^sitename\.net [NC]
  9. RewriteRule ^(.*)$ https://www.sitename.net/$1 [R=301,L]
  10.  
  11. RewriteRule ^(favicon\.ico|robots\.txt|sitemap\.xml|google.*\.html) - [NC,L]
  12. RewriteCond %{REQUEST_FILENAME} -f
  13. RewriteRule /*\.(css|js|gif|png|jpe?g|ico|svg|mp3|mp4|m4v|m4a|ogg|webm|zip|jar)$ - [NC,L]
  14. RewriteRule ^(.*)$ index.php [QSA,L]

Line 9 turns on the rewrite engine. IMPORTANT: If the Apache module rewrite isn't activated, this directive fails. The entire working of the site depends on it. Check the Apache error log.

The rules defined lines 11 to 13 and 15 to 17 send back all requests in HTTP and in HTTPS to the domain sitename.net to the full domain www.sitename.net.

Line 19 returns unchanged the access to the files favicon.ico, robots.txt and sitemap.xml as well as to the validation file of Google.

The lines 20 to 22 redirect all access paths to the file index.php except for a series of files whose names designate CSS or JavaScript files, files containing images, audios or videos, archives.

IMPORTANT: If the site has direct links to other types of files, remember to add their extensions to the list in rule line 21. Be careful with export files of a database or other sensitive files which could become accessible and be downloaded!

To force an access in HTTPS, replace the lines:

  1. RewriteCond %{HTTP_HOST} ^sitename\.net [NC]
  2. RewriteRule ^(.*)$ http://www.sitename.net/$1 [R=301,L]

by the line:

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

Delete the line:

  1. RewriteCond %{HTTPS} on
index.php
  1. define('ROOT_DIR', __DIR__);

Defines the constant ROOT_DIR to the value of the directory containing the website on the host system.

  1. set_include_path(ROOT_DIR . PATH_SEPARATOR . get_include_path());
  2. set_include_path(ROOT_DIR . DIRECTORY_SEPARATOR . 'includes' . PATH_SEPARATOR . get_include_path());
  3. set_include_path(ROOT_DIR . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR . get_include_path());

Adds ROOT_DIR and the directories library and includes to the PHP path.

  1. require_once 'bootstrap.php';
  2.  
  3. bootstrap();

Initializes the environment of the program with bootstrap.

  1. require_once 'engine.php';
  2.  
  3. dispatch($supported_languages); // see config.inc

Loads the functions of the engine and starts the execution of the request by passing the list of the supported languages to dispatch.

SEE ALSO

Overview diagram, bootstrap, engine, trace

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].