0

I have the following .htaccess file:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On
  RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^.*$ index.php [L]
</IfModule>

It redirects everything to index.php if it's not a file or a directory. It works fine, but when a file has an accent in its name it redirects the url to index.php, so the RewriteCond can't detect that it's an existing file. For example (both files exist):

This works: http://example.com/something.pdf (gives me the PDF)

But this doesn't: http://example.com/somethingá.pdf (redirects me to index.php)

The problem is that I don't have access to the web server conf, since it is on a webhosting server.

The system is Windows Server 2008 R2 Web Server Edition Service Pack 1 (by PhpInfo)

Web server: Microsoft-IIS/7.5

Fenistil
  • 3,734
  • 1
  • 27
  • 31
  • 1
    Apache version? Works fine for me using XAMMP (Apache 2.4.3) on a Win7 dev box. – CD001 Jul 06 '17 at 15:39
  • @CD001 Edited my post, but it's Microsoft-IIS/7.5. – Fenistil Jul 06 '17 at 16:03
  • 1
    That's your problem them, `.htaccess`, `mod_rewrite` and so on are Apache specific - IIS uses a *Web.config* XML file I believe. – CD001 Jul 07 '17 at 08:33
  • 1
    This might be useful: https://stackoverflow.com/questions/257936/htaccess-or-htpasswd-equivalent-on-iis – CD001 Jul 07 '17 at 09:10
  • @CD001 Based on the information you've provided I can fix it converting the .htaccess file to a web.config file. Please post it as an answer, so I can accept it. – Fenistil Jul 07 '17 at 13:42

1 Answers1

0

Based on CD001's comment, I've found out that however IIS can convert .htacess files automatically, but doesn't work 100% all the time. So I fixed the problem by converting the .htaccess file to a web.config file manually. The converted file is:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rule 1">
                    <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="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Save it as web.config in the root of your webpage to get it work and delete the .htacess.

Fenistil
  • 3,734
  • 1
  • 27
  • 31