Site ignoring htaccess redirects - need IIS web.config

I have recently updated a website, it was previously just a single page html file, it is now a single php page, but will expand to more pages in future.
So before there was just index.html, now there is just index.php
Things are set up so if you put in the site root address, you get index.php, but if someone follows an old link to they get 404.
I thought, no problem, just put a redirect in the htaccess. But it is not working. I have done this with other sites, but can’t get it working here.
I have tried a few different redirect methods, but nothing works.
Any clues?

Try this

RewriteEngine On
RewriteBase /
RewriteRule ^index\.html?$ / [NC,R,L]

Try playing about with this in your .htaccess file.

DirectoryIndex index.php index.html site-down.php

I have prevented Google’s duplicate warnings by setting the directory index to home and calling a cached home.html file.

Thanks, but I already tried that, it still gives me 404.
As a temporary measure I have made an index.html file with a meta tag to do the redirect. It works but I would prefer to do it with htaccess. I just can’t figure why its not working.

Just tried that and still get 404.
Could there be some setting that causes the htacces to be ignored?

Index.html should precede index.php, I copied and pasted on my tablet, sorry.

The idea is that if index.html exists that file is called first, then proceeds to the next specified file. As mentioned the first file tested for existence on my site is the renamed index.php results page to the static cached/home.html version. I could have called it Fred.html and it would have been called first :slight_smile:

DirectoryIndex index.html index.php site-down.php

I tried it like this, but it still does not work. Baffled by this one :confused:


DirectoryIndex index.html index.php site-down.php
I tried it like this, but it still does not work. Baffled by this one confused

I am surprised it is not working.

Try DirectoryIndex index.html in the first line of your .htaccess file.

If that does not work the try creating a simple Fred.html file and call that first with the DirectoryIndex directive.

Does .htaccess work at all on your server?
Try add this line to check (warning: you should have FTP/SSH access to remove that line later):

Deny From All

You should get 403 Forbidden error on your index.html after that
If no, check AllowOverride option for your host in Apache config

I don’t think that’s what OP’s problem is.

DirectoryIndex won’t help if the URL points to a file rather than a directory.

You’ll need to show your htaccess.

This works for me on my localhost

RewriteEngine On
RewriteRule "^index\.html$"  "fred.php"

I suspect not. Everything I have tried with htaccess has failed so far. I will try some of the suggestions.

I keep changing it to try different things. At the last attempt it looked like this:

# DirectoryIndex index.php
DirectoryIndex index.html index.php site-down.php

# RewriteEngine On
# RewriteBase /
# RewriteRule ^index\.html?$ / [NC,R,L]

The commented lines are what I tried previously (among other things).

The bottom 3 commented lines should have done the trick. Could mean that .htaccess files in general are disabled. Try megazoid’s test in post #9 to check if this is the case.

I tried this and it made no difference, so I guess the htaccess is being ignored completely.

At this time I only have FTP access to the site, I can’t log into the Control Panel or anything. I will try and get full access. In the mean time I will have to stick with the html redirect.

Yeah, it’s a common problem when your web root directory in Apache config has AllowOverride None option instead of AllowOverride All. If you’re not sure where to fix that I think you can contact technical support of your hosting company and get help from them.

The penny has dropped.
I just checked and found that the server is Microsoft-IIS/8.5 not Apache.
So now I have to learn how to do this with a Microsoft server.

Is seems that IIS uses a web.config file which is an XML file that does the same job as a htaccess file. This is new to me. I just had a go at creating one, uploaded it and got a 500 error, not on the index.html but the site root.

Has anyone any experience in how to create a web.config file for IIS? More specifically for the redirect task I want.
I can’t get anything to work, I just get errors (usually 500).

OK I think I have it now;

<?xml version="1.0" encoding="UTF-8"?>
      <httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
         <add wildcard="*.html" destination="/" />

This does it. Destination could be destination="/index.php" but I prefer to just go to the root. I guess the wildcard means any .html file will redirect, but that’s OK since there should not be others.