« Previous Next »

Thread: Moving from ISAPI_REWRITE

Last post 10-08-2008 11:16 AM by hooflung64. 11 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (12 items)

Sort Posts:

  • 10-03-2008, 10:21 AM

    Moving from ISAPI_REWRITE

    Hello,

    I am moving from Win2k3 x86 and IIS6/ISAPI_REWRITE to Win2k8 x64 and IIS7/RW and let me say thanks to the IIS team for listening to what developers needed. Being someone who loves Debian and Lighttpd for my own projects IIS6/ISAPI_REWRITE was a hard pill to swallow.

     I am enjoying developing my new projects in a complete Win2k8 environment. I use codeigniter which is an MVC framework for PHP. I have 64bit PHP running on IIS7 and the Rewrite Mod is installed. Everything works after I put CI on the system thus far. I would like to begin to migrate my rewriting rules from ISAPI_REWRITE to the IIS module.

     

    RewriteRule ^/jscalendar-1.0/(.*)$ /jscalendar-1.0/$1 [L]
    RewriteRule ^/tinymce/(.*)$ /tinymce/$1 [L]
    RewriteRule ^/media/(.*)$ /media/$1 [L]
    RewriteRule ^/system/(.*)$ /system/$1 [L]
    RewriteRule ^/css/(.*)$ /css/$1 [L]
    RewriteRule ^/images/(.*)$ /images/$1 [L]
    RewriteRule ^/upload/(.*)$ /upload/$1 [L]
    RewriteRule ^/lightbox2.04/(.*)$ /lightbox2.04/$1 [L]

    RewriteCond Host: (?:www\.)?myurl\.org
    RewriteRule ^(.*)$ /index.php?/$1

     

    I need each site to have its own installation of CodeIgniter and each site will need the directory rules. The URL friendly makes my site www.myurl.org/index.php? to www.myurl.org/index.php

     Can anyone help me with this?

     Thanks in advance!

    hooflung64

  • 10-03-2008, 12:47 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 664

    Re: Moving from ISAPI_REWRITE

    From these ISAPI_REWRITE rules it looks like you need to rewrite http://myurl.org/foo/bar to http://myurl.org/index.php?/foo/bar only if foo/bar does not exist as a static file or directory on a file system. If so, then I think you should be able to define this logic by using just one rewrite rule:

    <rule name="MyRule">
          <match url="^(.*)$" />
           <conditions>
                 <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                 <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                 <add input="{HTTP_HOST}" pattern="(?:www\.)?myurl\.org" />
            </conditions>
            <action type="Rewrite" url="index.php?/{R:1}" appendQueryString="false" />
     </rule>

    http://ruslany.net
  • 10-03-2008, 1:42 PM In reply to

    Re: Moving from ISAPI_REWRITE

     Thanks for the quick reply!

     This may indeed work for the URL. Indeed /foo/bar is not a file nor is it a directory. It is a class/method. So there would be a file named foo.php in the controller directory and inside that file there would be a bar() function.

     Ok so that should work for my site URL. Can you do an example for each one of the directory's I put above the URL example?

     Example is that in the root there would be images and javascript folders with files. So they do exist as directories and I need access to the files within them. Basically I am not sure if I would need to add REQUEST_FILENAMES for files and directories and not sure.

     Would it look like:

     <rule name="MyRule2">

    <match url="^/system/(.*)" />

    <action type="Rewrite" url="/system/{R:1}" appendQuerystring="false" />

    </rule>

     ?

     

    Also, since some of this stuff is javascript and will contain ajax code do I need to look into making appendQueryString="true" at all if they use GET?

     

    Thanks for your help so far!

    -hooflung64

  • 10-03-2008, 2:07 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 664

    Re: Moving from ISAPI_REWRITE

    I do not think there is a need for those rewrite rules at all. They do not change the requested URL; they are used just to prevent execution of last rule if any resource from those directories was requested.

    Take for example this rule:

    RewriteRule ^/images/(.*)$ /images/$1 [L]

    When requested URL path is /images/picture.jpg then it will rewrite it to the same path: /images/picture.jpg and then will stop evaluation of all subsequent rules (notice the [L] flag), thus preventing the very last rule used for rewriting to index.php from executing.

    The rule that I sent you should take care of that in a more cleaner way. 

    http://ruslany.net
  • 10-03-2008, 2:13 PM In reply to

    Re: Moving from ISAPI_REWRITE

     Well then that would be awesome!!!

     Thank you for clearing that up and if doesn't work as expected I will bump the thread later.

     Cheers!

    -hooflung64

  • 10-07-2008, 2:30 PM In reply to

    Re: Moving from ISAPI_REWRITE

     Well,

     I have the bare application setup on my development server which doesn't have a domain name.

     The part of my web config file for the rewrite rule is:

     

    <rewrite>
                <rules>
                    <rule name="Clean URL">
                        <match url="^(.*)$" />
                        <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="false" />
                    </rule>
                </rules>

    </rewrite>

     

    I can access the site from http://x.x.x.x:81/index.php and http://x.x.x.x:81/class/method but if I redirect from a class/method it gives me the http://x.x.x.x:81/index.php?/class/method 

     Is there a possibility that the rewrite rule isn't working. I installed the OS, put the IIS role, installed the rewrite module, then did the php. So I don't think I did anything out of order for it to not allow me to use my rule right off the bat.

  • 10-07-2008, 4:42 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 664

    Re: Moving from ISAPI_REWRITE

    The codeigniter mod_rewrite rules described here (http://codeigniter.com/wiki/mod_rewrite/) rewrite to index.php/$1. The provided example of ISAPI_Rewrite rules rewrite to index.php?/$1 (notice the question mark symbol). I do not think the question mark should be there. Have you tried removing the ? from the substitution url in the "Clean URL" rule?

    E.g. <action type="Rewrite" url="index.php/{R:1}" appendQueryString="false" />

    http://ruslany.net
  • 10-07-2008, 4:52 PM In reply to

    Re: Moving from ISAPI_REWRITE

     Some servers absolutely require the ? and some do not but work with or without it. IIS has been one that does demand the ? after index.php. I'll try it without it since this is version 7 but I don't think that is the problem.

  • 10-07-2008, 5:04 PM In reply to

    Re: Moving from ISAPI_REWRITE

     http://x.x.x.x:81/index.php/login/admin is now what happens when I go from http://x.x.x.x:81/admin

     I have a route rule that states if you are not logged in then you get sent to /login/

     It doesn't really matter if the method is wrong/nonexistant as long as it loads the proper view (it works in production this way on IIS 6 and isapi_rewrite). However, the index.php or index.php? still refuses to leave =(

  • 10-07-2008, 7:19 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 664

    Re: Moving from ISAPI_REWRITE

    Are you saying that when you request http://x.x.x.x/admin you get redirected to http://x.x.x.x/index.php/login/admin , correct? Is that the codeigniter that does the redirection?

    http://ruslany.net
  • 10-08-2008, 10:53 AM In reply to

    Re: Moving from ISAPI_REWRITE

     Yes that is correct. If you are not logged in to the site you are redirected to the login controller. The route override just says you go to the index method of login despite what might show up in the url as the method.

     After you login, you are sent back to the admin controller because that is what is passed is hardcoded in the login controller on successful login.

    x.x.x.x/admin failed login -> x.x.x.x/login/admin then have username/pass match -> x.x.x.x/admin

     This is what is supposed to happen. However, I am still getting x.x.x.x/index.php/login/admin on a redirect.

     

  • 10-08-2008, 11:16 AM In reply to

    Re: Moving from ISAPI_REWRITE

     I am an idiot. I didn't remove index.php from the $config['index_page'] = ""; line in the config.php file. This is what was forcing site_url() to force the index.php or index.php? into the URL.

     

    So far so good on the rewrite rule now that my id10t error is not affecting it.

     

    Cheers

Page 1 of 1 (12 items)
Microsoft Communities