Skip to content

Instantly share code, notes, and snippets.

@fenda
Last active June 6, 2023 13:27
Show Gist options
  • Select an option

  • Save fenda/8679492 to your computer and use it in GitHub Desktop.

Select an option

Save fenda/8679492 to your computer and use it in GitHub Desktop.

Revisions

  1. fenda renamed this gist Jan 29, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. fenda revised this gist Jan 29, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    # The following will allow you to use URLs such as the following:
    #
    # example.com/anything
    # example.com/anything/
    # example.com/link
    # example.com/link/
    #
    # Which will actually serve files such as the following:
    #
    # example.com/anything.html
    # example.com/anything.php
    # example.com/link.html
    # example.com/link.php
    #
    # But *only if they exist*, otherwise it will report the usual 404 error.

  3. fenda created this gist Jan 29, 2014.
    33 changes: 33 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    # The following will allow you to use URLs such as the following:
    #
    # example.com/anything
    # example.com/anything/
    #
    # Which will actually serve files such as the following:
    #
    # example.com/anything.html
    # example.com/anything.php
    #
    # But *only if they exist*, otherwise it will report the usual 404 error.

    Options +FollowSymLinks
    RewriteEngine On

    # Remove trailing slashes.
    # e.g. example.com/foo/ will redirect to example.com/foo
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ /$1 [R=permanent,QSA]

    # Redirect to HTML if it exists.
    # e.g. example.com/foo will display the contents of example.com/foo.html
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.+)$ $1.html [L,QSA]

    # Redirect to PHP if it exists.
    # e.g. example.com/foo will display the contents of example.com/foo.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.+)$ $1.php [L,QSA]