EllisLab text mark
Advanced Search
     
CSS path after IIS url rewrite
Posted: 15 April 2010 02:31 PM
Joined: 2010-01-20
34 posts

I followed the instructions on this page http://codeigniter.com/wiki/Miscellaneous/ and everything works fine for removing index.php from urls.

This has now caused my CSS file to not be found. The file is in a folder structure like this from the root

assets/css/stylesheet.css

I’ve tried the following

http://mysite.com/assets/css/stylesheet.css

/assets/css/stylesheet.css

assets/css/stylesheet.css

But none of those options work.

My web config file looks like this

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

    <
system.webServer>

        <
rewrite>

            <
rules>

                <
rule name="codeigniterRuleOne">

                    <
match url="(index.php|robots.txt|images|test.php)" />

                </
rule>

                <
rule name="codeigniterRuleTwo">

                    <
match url=".*" />

                    <
action type="Rewrite" url="index.php/{r:0}" appendQueryString="false" />

                </
rule>

            </
rules>

        </
rewrite>

    </
system.webServer>

</
configuration

Can anyone suggest how to fix this? Thanks for any help

 
Posted: 15 April 2010 02:39 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2009-12-08
1804 posts

Try adding the assets directory to the rule that doesn’t get rewritten:

<match url="(index.php|robots.txt|images|test.php|assets)" /> 
 Signature 

@basdflasjk | BitAuth: Authentication and Role-based Permissions | Session Library Replacement


Please read the User Guide! (Upgrading from a previous version?)

 
Posted: 15 April 2010 03:05 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2010-01-20
34 posts
noctrum - 15 April 2010 06:39 PM

Try adding the assets directory to the rule that doesn’t get rewritten:

<match url="(index.php|robots.txt|images|test.php|assets)" /> 

Thanks for your quick reply. I added assets to the rule but it’s still not working, even though when I test the pattern in IIS it says it is ok.

Any other ideas?

Thanks

 
Posted: 15 April 2010 03:08 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-12-08
1804 posts

When you go to http://mysite.com/assets/css/stylesheet.css in your browser, does it load? Do you get an IIS 404? CI 404?

 Signature 

@basdflasjk | BitAuth: Authentication and Role-based Permissions | Session Library Replacement


Please read the User Guide! (Upgrading from a previous version?)

 
Posted: 15 April 2010 03:09 PM   [ # 4 ]   [ Rating: 0 ]
Joined: 2010-01-20
34 posts

I get an IIS 404

 
Posted: 15 April 2010 03:58 PM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2009-12-08
1804 posts

Interesting… I’m not familiar enough with IIS to be any more help, I don’t think

 Signature 

@basdflasjk | BitAuth: Authentication and Role-based Permissions | Session Library Replacement


Please read the User Guide! (Upgrading from a previous version?)

 
Posted: 15 April 2010 04:14 PM   [ # 6 ]   [ Rating: 0 ]
Joined: 2010-01-20
34 posts

No problems, thanks for your help so far. When I read your first post I was convinced that would work perfect first time.

Thanks again

 
Posted: 15 April 2010 04:52 PM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2009-12-08
1804 posts

Might the problem be that you don’t have an action for the first rule? Something like:

<rule name="codeigniterRuleOne">
    <
match url="(index.php|robots.txt|images|test.php|assets)" />
    <
action type="none"/>
</
rule

(again, not real familiar with IIS, syntax may be wrong)

 Signature 

@basdflasjk | BitAuth: Authentication and Role-based Permissions | Session Library Replacement


Please read the User Guide! (Upgrading from a previous version?)

 
Posted: 15 April 2010 05:09 PM   [ # 8 ]   [ Rating: 0 ]
Joined: 2010-01-20
34 posts

Thanks for coming up with another good suggestion, unfortunately that one produces a 500 error.

I created the rules in the IIS GUI so I expect the actual rules to have been written to the config file correctly.

 
Posted: 15 April 2010 05:25 PM   [ # 9 ]   [ Rating: 0 ]
Joined: 2010-01-20
34 posts

Right, I’ve got it sorted.

The rules were in the correct order I needed to tell it to stop processing rules after it matched the first one. I did this in the IIS GUI, it’s just a checkbox.

And this is the resultant config file

<?xml version=“1.0” encoding=“UTF-8”?>

<configuration>

  <system.webServer>

      <rewrite>

        <rules>

          <clear >

          <rule name=“codeigniterRuleOne” stopProcessing=“true”>

              <match url=“index.php|robots.txt|images|test.php|assets” >

              <conditions logicalGrouping=“MatchAll” >

          </rule>

          <rule name=“codeigniterRuleTwo”>

              <match url=”.*” >

              <conditions logicalGrouping=“MatchAll” >

              <action type=“Rewrite” url=“index.php/{r:0}” appendQueryString=“false” >

          </rule>

        </rules>

      </rewrite>

  </system.webServer>

</configuration>

Thanks to noctrum for his very good suggestions which helped me whittle down the options to find the solution.