0

I have a site and I want to redirect everything to /index.html.

I'm replacing an old site so some visitors may try to access dead urls. How can I do this through .htaccess?

Also, is there a way to rewrite the url in the process so they just see http://www.example.com and not whatever they originally tried to access?

Thanks, Howie

Wooble
  • 87,717
  • 12
  • 108
  • 131
Ward
  • 3,318
  • 3
  • 30
  • 50

2 Answers2

1

This should do the job:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.html

the index.html shall stay in the same directory of the htacess

Simone
  • 2,261
  • 2
  • 19
  • 27
  • doesn't seem to work. I get a 500 Internal Error. Any other ideas? – Ward Sep 01 '11 at 18:51
  • It should work, it's a very standard code; you should check the path of the index.html page; can you post the directory structure? – Simone Sep 01 '11 at 18:53
  • My directory structure is just: /index.html, /img.jpg, /favicon.ico and /.htaccess. I want someone who visits http://www.example.com/something to go to http://www.example.com – Ward Sep 01 '11 at 19:17
  • i edited the answer, did you checked again if it works? – Simone Sep 01 '11 at 19:19
  • yeah, thanks tried the latest. It works for /something.html, but not /something – Ward Sep 01 '11 at 19:20
  • "something" should be the name of a page? or of a directory? – Simone Sep 01 '11 at 19:24
  • well the original site was drupal so "/something" would have been a page, not a real directory. I added RewriteBase / and maybe its a coincidence, but /something.html and /something work, but /something/somethingelse doesn't - same deal with /something/ vs /something – Ward Sep 01 '11 at 19:36
  • Try "RewriteBase /something/" and then "Rewrite Rule .* something" – Simone Sep 01 '11 at 19:40
  • the problem with that is I don't know what the urls will be. A visitor to the previous site could have bookmarked anything. I just need it all to point to index.html. – Ward Sep 01 '11 at 19:49
  • redirectMatch 301 ^(.*)$ index.html – Simone Sep 01 '11 at 20:03
0
  1. Open IIS.
  2. Select your website in left pane.
  3. In IIS 7 choose option Default documents in middle box and add your required index page. In IIS 3 right click on website in left pane and choose properties>home directory> then add your index page name and bring it to top (Top for priority).
  4. In the same page you have option to redirect your URL to another URL
Mal
  • 533
  • 1
  • 12
  • 27