Skip to content

Instantly share code, notes, and snippets.

@rwatts3
Forked from stevewithington/muraHTACCESSFile
Last active August 29, 2015 14:16
Show Gist options
  • Save rwatts3/b8ec9f3c423aebbbed52 to your computer and use it in GitHub Desktop.
Save rwatts3/b8ec9f3c423aebbbed52 to your computer and use it in GitHub Desktop.
# Also refer to https://gist.github.com/stevewithington/5060602 if you wish to allow for mixed siteIDs in URLs
# Apache mod_rewrite Docs: http://httpd.apache.org/docs/current/rewrite/
# Intro: http://httpd.apache.org/docs/current/rewrite/intro.html
# Flags: http://httpd.apache.org/docs/current/rewrite/flags.html
Options All -Indexes
Options +FollowSymLinks
# -------------------------------------------------------------------------------
# MURA REWRITE OPTIONS
#
# NOTE: If running on Tomcat and you will have any site(s) with their SiteID in
# the URL, you will need to add a custom servlet mapping for each one.
# For instructions, visit: http://docs.getmura.com/v6/installation-setup/how-to-add-a-servlet-mapping-for-your-siteid-to-tomcat/
# -------------------------------------------------------------------------------
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Is the request for a non-existent file or non-existent directory?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# OPTION 1 :: WITHOUT SiteID
# Set both siteIDInURLS and indexFileInURLs to 0 in your
# /config/setting.ini.cfm and reload Mura
RewriteRule ^(.*) /index.cfm/$1 [NC,QSA,PT]
# OPTION 2 :: WITH SiteID
# Set indexFileInURLs to 0 in your /config/setting.ini.cfm and reload Mura.
#RewriteRule ^([a-zA-Z0-9_\-]{1,})/(.*) /$1/index.cfm/$2 [NC,QSA,PT]
# OPTION 3 :: Advanced Configuration ::
# IF you want to have SiteID for SPECIFIC SITES ONLY, but not all of them
# you need to add a custom getURLStem() method to the Site's contentRenderer.cfc
# Then, you need to ENABLE OPTION 1 above, and add a custom rewrite rule for each site:
RewriteRule ^SomeSiteID/(.*) /SomeSiteID/index.cfm/$1 [NC,QSA,PT]
RewriteRule ^AnotherSiteID/(.*) /AnotherSiteID/index.cfm/$1 [NC,QSA,PT]
# 404 :: Pass the requested URI as a query string
# This assumes you have a custom 404.cfm file at the root of your site
#RewriteRule (.*) 404.cfm?%{REQUEST_URI}?%{QUERY_STRING}
# Forbid executable files from being downloaded
RewriteRule \.exe - [F]
</IfModule>
# -------------------------------------------------------------------------------
# UTF-8 encoding
# -------------------------------------------------------------------------------
# Use UTF-8 encoding for anything served text/plain or text/html
AddDefaultCharset utf-8
# Force UTF-8 for a number of file formats
AddCharset utf-8 .css .js .xml .json .rss .atom
<cfscript>
// Drop these methods into your Site's contentRenderer.cfc for the sites that you WANT SiteIDs in URL
public string function getURLStem(required siteid, filename='') {
var sid = '/' & arguments.siteid;
var fname = getCleanFilename(arguments.filename);
// you want to make it so that it **always** adds in the SiteID
return !Len(fname) ?
sid & '/' :
application.configBean.getIndexFileInURLs() ?
sid & '/index.cfm' & fname :
sid & fname;
}
private string function getCleanFilename(filename='') {
var fn = arguments.filename;
if ( Len(fn) ) {
if ( Left(fn, 1) != '/' ) {
fn = '/' & fn;
}
if ( Right(fn, 1) != '/' ) {
fn = fn & '/';
}
}
return fn;
}
</cfscript>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--
NOTES:
- This only works for IIS7+
- If you wish to allow for missing "index.cfm" from the URL:
* make sure you have "IIS URL Rewrite Module 2.0" installed.
* Download available at http://www.iis.net/download/URLRewrite
* rename this document to "web.config" without the quotation marks
* choose one of the rewrite rules below to enable
-->
<system.webServer>
<rewrite>
<rules>
<!--
NOTES:
- update /config/settings.ini.cfm with the settings below:
siteidinurls=0
indexfileinurls=0
- reload Mura CMS
-->
<rule name="Remove SiteID AND index.cfm from URL" enabled="true" stopProcessing="true">
<match url="^([a-zA-Z0-9_\-/].+)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<!--
This is the key! We need to exclude any siteid's we want to appear in the URL
from being processed here so that the next rule will kick in and apply.
-->
<add input="{REQUEST_URI}" pattern="^/(someSiteID/|anotherSiteID/)" negate="true" />
</conditions>
<action type="Rewrite" url="/index.cfm/{R:1}" appendQueryString="true" />
</rule>
<rule name="Remove ONLY index.cfm from URL" enabled="true">
<match url="^([a-zA-Z0-9_\-]{1,})/(.*)" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="/{R:1}/index.cfm/{R:2}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<defaultDocument>
<files>
<remove value="index.cfm" />
<add value="index.cfm" />
</files>
</defaultDocument>
<staticContent>
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment