1

Is it possible to redirect (via a Rewrite Cond?) users to another URL for help if an index.html or index.php file doesn't exist within their home directory?

Thanks Greg

gregory
  • 13
  • 1
  • 3

2 Answers2

0

You need to use the [L] flag.

http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_l

A similar case is illustrated here:

https://stackoverflow.com/questions/2118898/if-no-file-rewrite-url

Stephan
  • 999
  • 7
  • 11
0

The -f mode of RewriteCond can check for file existence. You can use this to test for a file's existence. For instance, if the user requests a directory that has no index, you can redirect them with something along these lines:

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/index\.(html|php) !-f
RewriteRule ^ http://example.com/something-blew-up.html [R=302]
Shane Madden
  • 112,982
  • 12
  • 174
  • 248
  • cool, thanks! what does `RewriteCond %{REQUEST_FILENAME} -d` do? This is for _any_ request? for instance, would the follow (assuming valid) urls get caught http://example.com/test/info.php or http://example.com/info.php – gregory Feb 06 '13 at 17:21
  • @gregory The two conditions work as an "AND" pair -- it's saying, if your request is for a directory (the first condition) and there's no index file in the directory (the second condition) then send the redirect. So valid requests should never get caught, since the first rule, the directory check, won't match. – Shane Madden Feb 07 '13 at 00:36
  • Thanks! Makes sense. I wonder, if it is possible to make the browser always revalidate so the redirect isn't cached. Maybe that is for another s.o. question. – gregory Feb 08 '13 at 02:28