简体   繁体   中英

IIS Intermittent Change of Rewrite Settings

I have my application build based on CodeIgniter, and the application running on IIS7.5 on a Windows Server 2008 R2 Standard.

We also have 4 separate databases, one of each operating state which runs on the same server. (i know probably not best practice, but its what i have been given to work with. i was not original designer).

So my folder structure goes like this, and is duplicated for each state.

wwwroot/
  |
  |-{STATE}/
  |----|index.php //CI Index.php
  |-{STATE}/
  |----|index.php //CI Index.php

The state folders are windows directories with names written in Capitals.

each folder has a web.config file to rewrite uri requests to index.php

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpErrors errorMode="Detailed" />
        <asp scriptErrorSentToBrowser="true" />

        <rewrite>
        <rules>
            <rule name="RuleRemoveIndex" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="true" />
                <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php?{R:1}" appendQueryString="true" />
            </rule>
        </rules>
        </rewrite>
    </system.webServer>
</configuration>

now here is where i am confused.

The application some times works, and sometimes does not work depending on weather the state component (https://{SUB}.{DOMAIN}:{PORT}/{STATE}/{URI}) is written in capitals or not.

When i originally put it up on the server, i tested it with lower case letters {state} and everything worked fine. I came back the next day, and found that using the lower case letters would give me a CodeIgniter 404 error. But if i used Capital letters {STATE} it would work find. and then it would change around again later.

after doing some url rewite testing using same principles here: http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module but changed to php, i noticed that

I also did some URL REWRITE testing to see what the outcomes of the URL Rewrites were, based on the aspx version here: http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module but changed to php. What i found was that $_SERVER['SCRIPT_NAME'] was retaining the first way in which the the {STATE} was being type (Capital or lower case). My temporary fix is simply what i am sure is bad practice, I added this script to the start of my index.php file

$_script_name = $_SERVER['SCRIPT_NAME'];
$_script_name_array = explode('/', $_script_name);
$_script_name_array[1] = strtolower($_script_name_array[1]);
$_script_name = implode('/', $_script_name_array);
$_SERVER['SCRIPT_NAME']=$_script_name;

which has half fixed the issue, it basically forces the use of states in lower case. It would be nice if a solution could be found so that it doesn't matter if the {state} is written in capitals or not.

I was hoping someone on here might have some idea's.

IIS Rewrite would be handy in this case

Add the following code to your web.config file located in the root of your web folder.

<rule name="LowerCaseRule" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>

Here URL Rewrite you can find more details on it. Hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM