we have a system, based on Moodle platform, where files are referenced like this:
http://[server]/file.php/3/LR4/info/index.html
Now, this works great, however some of our teachers by mistake used backward slashes then they organized their parts, that means, that some pages are referenced like this:
http://[server]/file.php/3/LR4\info\index.html
That worked fine while we were using Windows Server+IIS. However, then we switched to Linux+Apache, Apache does not seem to handle them correctly. In other words, it does not display images placed on the page, since their urls are relative, and Apache cannot reconstruct the full URL, if the base url contains backward slashes. So the page is just text, no pictures.
If I replace manually the backward slashes to direct in URL in browser address line, everything still works fine. However, we have too many pages like that. We need something to rewrite URL. I thought of Apache mod rewrite. What I basically need is three lines in code:
RewriteEngine on
RewriteCond %{THE_REQUEST} [???]
RewriteRule ??? [R]
What I need is the regular expression for RewriteCond that would make the engine react just for the URLs that contain phrase file.php and some backward slashes after that. And for the RewriteRule I need something that would replace at least one backward slash with direct (leaving everything else untouched) and make a redirect after that. But I can’t seem to construct the correct expressions – can anyone help?
If you’re set on doing something through .htaccess then the following should work.
Another option would be to edit the file.php script and translate all ‘\’ to ‘/’ in the PATH_INFO or REQUEST_URI variables or however it determines which file to display.