2013-10-29 09:55
浏览 73


I have a subdomain, which, as the name suggests, delivers images to all of the other subdomains on

At the moment, I have set up the virtual host to apply all custom error documents from the parent domain like so:

ErrorDocument 400
ErrorDocument 401
ErrorDocument 403
ErrorDocument 404
ErrorDocument 500
ErrorDocument 405
// And so on...

However, what I would like to do is redirect the visitor if they do not specify any file or directory. In other words, if they go to, they will be redirected to

Example: will redirect to

but will not redirect

The reason why I only want to redirect the first page is simply because, if you do not specify a document/directory, it shows the default Apache Server Test page instead of showing an error page.

So, in short, how can I redirect a domain only if no file/directory has been specified in the URL?

Or, how can I prevent the default Apache Server Test page from showing when no file/directory has been specified?

Last Resort

If I am unable to achieve this using my .htaccess, then I will just add a php page to teh root directory or the images subdomain and then just redirect from there...

Further Information

I have read elsewhere that by specifying a 403 error document, then the Apache Server Test page will not be shown. Well this has not worked as I have specified the error and I am still seeing the test page...

图片转代码服务由CSDN问答提供 功能建议

我有一个子域 ,顾名思义, 将图像传送到example.com上的所有其他子域。


  ErrorDocument 400
ErrorDocument 401
ErrorDocument 403 http:  //
ErrorDocument 404
ErrorDocument 500
ErrorDocument 405 http  :// 

但是,我想要做的是重定向 访问者,如果他们没有指定任何文件或目录。 换句话说,如果他们转到,他们将被重定向到。


\ n



我只想重定向第一页的原因仅仅是因为, 如果您没有指定文档/目录,它将显示默认的Apache Server Test页面,而不是显示错误页面。

因此,简而言之,如何 如果URL中没有指定文件/目录,我可以重定向域 吗?

或者,如何防止默认的Apache Server Test页面显示 什么时候没有指定文件/目录?


如果我无法使用我的.htaccess实现这一目的,那么我只会添加 一个php页面到根目录或图像子域,然后从那里重定向... 更多信息

我在其他地方读过,通过指定 403 错误文档,将不会显示Apache Server Test页面。 好吧,这没有用,因为我已经指定了错误,我仍然看到测试页...

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • douping1993 2013-10-29 10:02

    Line by line we have:

    1. turn rewrite engine on
    2. is the request a file that doesnt exist
    3. is the request a directory that doesnt exist
    4. If so then redirect to, this is the last rule.

      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ [L]

    p.s. if will not redirect as it exists then wont either.

    I suggest creating an index.php and do:

    解决 无用
    打赏 举报

相关推荐 更多相似问题