Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@earth3300
Last active July 20, 2020 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save earth3300/55cc52d661558f98df4622d6853fc4d0 to your computer and use it in GitHub Desktop.
Save earth3300/55cc52d661558f98df4622d6853fc4d0 to your computer and use it in GitHub Desktop.
# Rewrite all requests to /foo
# Rewrite to the cached file if it exists and is not a post or attachment.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# RewriteCond %{REQUEST_METHOD} !=POST
# RewriteCond %{QUERY_STRING} !.*=.*
# RewriteCond %{DOCUMENT_ROOT}/$1/index.html -f
# RewriteRule ^(.*) /$1/index.html [L]
</IfModule>
# Rewrite all requests to /foo
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{SERVER_NAME} www.foo.tld
RewriteCond %{REQUEST_URI} !^/foo/
RewriteRule ^(.*)$ /foo/$1 [L]
</IfModule>
# Server Configuration for the Site Root
#
# Use when all site files are placed in a directory.
# The <IfModule> is required for the site to work.
# The entire site can be shunted to a new /{dir}/ if needed.
#
# File: /.htaccess (Root)
# Created: 2020-07-20
# Time 18:52 UTC
# Lines: 22
# Length: 552
# Rewrite all requests to /{dir}/
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{SERVER_NAME} www.foo.tld
RewriteCond %{REQUEST_URI} !^/{dir}/
RewriteRule ^(.*)$ /{dir}/$1 [L]
</IfModule>
# A generic backup is at: /.htaccess-root.
@earth3300
Copy link
Author

earth3300 commented Jul 20, 2020

Each line is required. See:

https://github.com/earth3300/ec01/wiki/Forward-Slash

for a discussion.

@earth3300
Copy link
Author

.htaccess-dir-cached is a snippet designed to look first for and return a cached file, but only if the request is not a POST request or an attachment. An additional line which is platform specific and related to cookies is excluded from this snippet: (RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment