Skip to content

Commit

Permalink
add IIS compatibility; requires url_rewrite module; thanks to Todd Gi…
Browse files Browse the repository at this point in the history
…ardina, Todd's IT
  • Loading branch information
dleffler committed Jan 17, 2018
1 parent 773a318 commit a4d50c2
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
7 changes: 5 additions & 2 deletions framework/core/subsystems/expRouter.php
Expand Up @@ -837,15 +837,18 @@ public function getPageByName($url_name) {
* if we got an old school url, it will only contain the 'index.php'
*/
private function buildSEFPath () {
// Apache
if (strpos($_SERVER['SERVER_SOFTWARE'],'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'],'WebServerX') !== false) {
// Apache or Microsoft-IIS -- Microsoft-IIS added by Todd Giardina, Todd's IT 12-17-2017
if (strpos($_SERVER['SERVER_SOFTWARE'],'IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'],'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'],'WebServerX') !== false) {
switch(php_sapi_name()) {
case "cgi":
$this->sefPath = !empty($_SERVER['REQUEST_URI']) ? urldecode($_SERVER['REQUEST_URI']): null;
break;
case "cgi-fcgi":
if (isset($_SERVER['REDIRECT_URL']) && $_SERVER['REDIRECT_URL'] != PATH_RELATIVE.'index.php') {
$this->sefPath = urldecode($_SERVER['REDIRECT_URL']);
} elseif (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != PATH_RELATIVE.'index.php') {
$url = explode('?', $_SERVER['REQUEST_URI']); // note the 'query' should already be in $_GET?? so remove it
$this->sefPath = urldecode($url[0]);
} elseif (!empty($_ENV['REQUEST_URI'])) {
$this->sefPath = urldecode($_ENV['REQUEST_URI']);
} else {
Expand Down
77 changes: 77 additions & 0 deletions web.config
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP/S to HTTPS Redirect" enabled="false" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Move from subfolder to root" enabled="false" stopProcessing="true">
<match url="^testfolder/(.*)$" />
<action type="Redirect" url="/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Change to www." enabled="false" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Remove www." enabled="false" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" />
</conditions>
<action type="Redirect" url="http://example.com/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Convert index.html call">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="index.html" appendQueryString="true" />
</rule>
<rule name="Convert *.html call">
<match url="^([^.]+)$" ignoreCase="false" />
<action type="Rewrite" url="{R:1}.html" appendQueryString="true" />
</rule>
<rule name="Psuedo login.php" enabled="false">
<match url="^login.php$" ignoreCase="false" />
<action type="Rewrite" url="login/showlogin" />
</rule>
<rule name="Main SEF URL Rule" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{URL}" pattern="\.(css|js|pdf|shtml|htc)$" negate="true" />
<add input="{URL}" pattern="\.(jp?g|gif|png|tiff)$" negate="true" />
<add input="{URL}" pattern="\.(mp3|mp4|webm|ogv|flv|f4v)$" negate="true" />
<add input="{URL}" pattern="^/robots\.txt$" negate="true" />
<add input="{URL}" pattern="^/favicon\.ico$" negate="true" />
<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="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
</files>
</defaultDocument>
<httpErrors>
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="403" subStatusCode="-1" />
<error statusCode="403" prefixLanguageFilePath="" path="/index.php?controller=notfound&amp;action=handle_not_authorized&amp;error=403" responseMode="ExecuteURL" />
<error statusCode="404" prefixLanguageFilePath="" path="/index.php?controller=notfound&amp;action=handle&amp;error=404" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/index.php?controller=notfound&amp;action=handle_internal_error&amp;error=500" responseMode="ExecuteURL" />
</httpErrors>
<staticContent>
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
</staticContent>
</system.webServer>
</configuration>

0 comments on commit a4d50c2

Please sign in to comment.