.htaccess (linuxfront-v2-logistics) 📄

✨ Overview

This Apache configuration file enables URL rewriting and sets directory options for the linuxfront-v2-logistics application. It implements a front-controller pattern, routing most requests to route.php. Static assets and special files are served directly.

Options +FollowSymLinks
Options -MultiViews
RewriteEngine On

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

#RewriteCond $1 !^(route\.php|fonts|images|css|robots\.txt)
RewriteCond $1 !^(route\.php|fonts|images|css|howie|robots\.txt|^$)
RewriteRule ^(.*)$ /route.php?$1 [L,NC,QSA]

🛠 Configuration Directives

The top section defines core Apache behaviors:

Directive Purpose
Options +FollowSymLinks Allows Apache to follow symbolic links.
Options -MultiViews Disables content negotiation via MultiViews.
RewriteEngine On Activates the rewrite engine (mod_rewrite).

🌐 WWW Redirection (Commented)

Optional rules to enforce the www. prefix are included but commented out. Uncomment to redirect all traffic to www.yourdomain.com:

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

🚫 Excluding Assets from Rewrite

To serve static resources directly, the rewrite skips requests matching:

  • route.php (the front controller)
  • fonts/, images/, css/ directories
  • howie/ directory (custom widget or module)
  • robots.txt file
  • Empty URI (the site root)

These exclusions prevent unnecessary routing of assets .

🔄 Front Controller Routing

Requests not matching the exclusions are rewritten to route.php, preserving the original path and query string:

Condition Rewrite
`RewriteCond $1 !^(route.php fonts
RewriteRule ^(.*)$ /route.php?$1 [L,NC,QSA] Forward all other requests to the front controller
  • [L]: Last rule
  • [NC]: Case-insensitive match
  • [QSA]: Append original query string

🛣 Request Flow

A simplified flow of how Apache handles incoming requests:

flowchart TD
  A[Client Request] --> B{URI matches exclusion?}
  B -- Yes --> C[Serve asset directly]
  B -- No  --> D[Rewrite to /route.php?{URI}]
  D --> E[Front Controller (route.php) processes request]

The .htaccess directives tie closely to these files:

  • route.php: The front-controller script that interprets the rewritten URI and includes the appropriate PHP page or asset .
  • inc/config.php: Defines constants (e.g., SITE_DIR, TEMPLATE_DIR) and database settings used by route.php and other includes.

💡 Best Practices

  • Disable MultiViews to avoid accidental file matches.
  • Exclude real assets (CSS, JS, images) from rewrites for performance.
  • Preserve query strings with [QSA] to maintain parameters.
  • Use a single front controller (route.php) to centralize routing logic.