IIS Web Configuration (web.config)

This web.config file configures URL rewriting and static content handling in IIS for the linuxfront-v2-logistics application. It ensures consistent hostnames, routes requests through a central route.php, and serves video files with correct MIME types.


✨ Overview

  • Applies to the <system.webServer> section in IIS.
  • Uses the URL Rewrite Module to:
    • Enforce a canonical hostname (www.freightanywhere.com).
    • Route dynamic requests through route.php.
  • Defines custom MIME mappings for video extensions.

🔄 URL Rewrite Rules

The <rewrite> section contains two key rules:

Rule Name Purpose
Canonical Host Name Redirect non-www.freightanywhere.com requests to www
Rewrite to route.php Funnel PHP/JS requests (excluding specific paths) via route.php

1. Canonical Host Name

This rule ensures every request uses the www subdomain.

<rule name="Canonical Host Name" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTP_HOST}" negate="true" pattern="^www\.freightanywhere\.com$" />
  </conditions>
  <action type="Redirect" url="http://www.freightanywhere.com/{R:1}" redirectType="Permanent" />
</rule>
  • Match: All URLs ((.*)).
  • Condition: Host is not www.freightanywhere.com.
  • Action:
    • Type: Permanent redirect (301).
    • Target: http://www.freightanywhere.com/{R:1} (preserves path).

Why?

  • Improves SEO by avoiding duplicate content.
  • Provides a single, canonical domain for cookies, caching, and analytics.

2. Rewrite to route.php

This rule rewrites incoming PHP/JS requests (except specific paths) to a central router.

<rule name="Rewrite to route.php">
  <match url="^(.*).php|^(.*).js$"/>
  <conditions>
    <add input="{REQUEST_URI}" negate="true" pattern="carrier-admin" />
    <add input="{REQUEST_URI}" negate="true" pattern="mediaplayer" />
    <add input="{REQUEST_URI}" negate="true" pattern="test.php" />
  </conditions>
  <action type="Rewrite" url="route.php/{R:1}" appendQueryString="true" />
</rule>
  • Match:
    • URLs ending with .php or .js.
  • Conditions: Exclude requests containing:
    • carrier-admin
    • mediaplayer
    • test.php
  • Action:
    • Type: Internal rewrite (no client redirect).
    • Target: route.php/{R:1} (appends the original path).
    • Query String: Preserved (appendQueryString="true").

Use Case

  • Centralizes routing logic in route.php.
  • Enables clean URLs and unified request handling.
  • Excludes administrative or media-player resources from routing.

🎥 Static Content (MIME Types)

Ensures IIS serves video files with correct MIME types:

<staticContent>
  <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
  <mimeMap fileExtension=".m4v" mimeType="video/m4v" />
</staticContent>
File Extension MIME Type Purpose
.mp4 video/mp4 Standard MP4 video format
.m4v video/m4v Apple-style MPEG-4 video container

Why?

  • Prevents “download” prompts in browsers.
  • Allows HTML5 video playback with correct codec identification.

🚀 Summary

  • Canonical Host Name
    Redirects to www.freightanywhere.com (SEO friendly).
  • Rewrite to route.php
    Channels most PHP/JS requests through a central router.
  • Custom MIME Types
    Supports HTML5 playback of .mp4 and .m4v files.

This configuration optimizes request routing, enforces a consistent domain, and ensures proper media delivery for the linuxfront-v2-logistics application.