moodle-local_cleanurls icon indicating copy to clipboard operation
moodle-local_cleanurls copied to clipboard

Rewrite rules problem on win server

Open fliegerrollo opened this issue 7 years ago • 3 comments

Hi I am using Moodle 3.3 on windows server 2012 R2. I installed this plugin moodle-local_cleanurls a few days ago an try to get it work.

Snippet out of my web.config:

<rule name="SEO-SEF urls Rule" stopProcessing="false">
  <match url="^(.*)$" ignoreCase="false" />
  <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="local/cleanurls/router.php?q={R:1}" appendQueryString="true" />
</rule>

Using this it works on cours pages like "https://www.mymoodle.com/course/Healthcare-17" (Original url= "https://www.mymoodle.com/course/view.php?id=10") But does not work on pages like "https://www.mymoodle.com/course/healthcare/page/26-about_us" (Original url= "https://www.mymoodle.com/mod/page/view.php?id=26") ---I get an http error 500!

When I change the <action> rewriter rule line to

<action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />

it is yust vice-versa. For both cases my Clean Urls setting page says: "Rewrite function is configured properly (outbound links)" Nevertheless in very top of setting page it shows: "Fetch an existing file : FAILED Fetch an existing directory without slash : FAILED Fetch an existing directory with slash : FAILED Fetch an invalid path : FAILED Fetch Clean URLs self test : FAILED Test rewrite without parameters : FAILED Test rewrite without a simple parameter : FAILED Test rewrite with 'x & y/z' as a parameter value : FAILED"

On Clean URLs Webserver Test Debug Information I get


Verbose Mode! GET: https://www.mymoodle.com/local/cleanurls/tests/webserver/index.php *** DATA DUMP: Error fetching URL!

Actual: Expected: [] Fetch an existing file : FAILED GET: https://www.mymoodle.com/local/cleanurls/tests/webserver *** DATA DUMP: Error fetching URL!

Actual: [0;F;F] Expected: [301;T;T] Fetch an existing directory without slash : FAILED GET: https://www.mymoodle.com/local/cleanurls/tests/webserver/ *** DATA DUMP: Error fetching URL!


and some other beside this.

I do not know what that means and what setting I should derive out of that. my config.php is set as mentioned in plugin documentation:

++++++ global $CFG; if (!isset($ CFG)) { $CFG=new std Class(); } ...other config settings $CFG->urlrewriteclass = '\local_cleanurls\url_rewriter'; ++++++

I want the plugin to work on both kinds of pages, ...course/view pages and ...mod/page/view pages What setting am I missing? I am not very well versed in rewrite rules. :-( I guess something is missing or wrong in teh rewrite rules?

Can anybody help please. Any hint very welcome!

Thank you Rolf

fliegerrollo avatar Jun 05 '17 09:06 fliegerrollo

hi @fliegerrollo,

What you've done looks good from my superficial windows knowledge and based of the same kind of thing in the drupal documentation:

https://www.drupal.org/docs/7/configuring-clean-urls/clean-urls-with-iis

One thing to investigate in the first instance is that the very first test is failing which is purely testing that the test script can 'curl' itself. This doesn't involve the clean urls at all, so I suspect that there is some sort of networking or dns / routing issue which you nee to solve first. Once the first test is green then the others should make more sense.

brendanheywood avatar Jun 05 '17 23:06 brendanheywood

Thank you Brendan.

In the mean time I found a closed issue #28 from June-20-2016 where similar problem has been discussed and came out with a success. After all efforts using other rewriterules came out unsatisfying, I now also tried changing moodle->mod->page->view.php from "require('../../config.php')" to "require_once('../../config.php')" and everything turns out fine. All pages are rewritten as desired. My tests are showing no other effect on any page. So I will continue using this little hack. Funny thing, but successful.

So thanks again for your assistance. Whishing you a nice week

Rolf

fliegerrollo avatar Jun 06 '17 05:06 fliegerrollo

@fliegerrollo great - but be aware that the proper fix means that it works will all the scripts which use require(), mod_page isn't the only script so be aware that this may break on other pages. It would be good to get some documented support for IIS into the readme file as well

brendanheywood avatar Jun 06 '17 05:06 brendanheywood