【问题标题】:Redirect domain to 404 generic page将域重定向到 404 通用页面
【发布时间】:2012-12-12 20:55:35
【问题描述】:

我有我的网站 (a.com)。另一个人将您的域 (b.com) 指向我的服务器。这是错误的。

是否可以将来自 b.com 的所有流量重定向到通用 404 页面?认为这可以通过文件 htaccess 实现

谢谢!

编辑

我能做到吗?

RewriteEngine On
RewriteRule ^(.*)$ http://www.b.com/$1 [R=404,L]

RewriteCond %{HTTP_HOST} ^www.b.com [nocase]
RedirectMatch 404 ^(.*)

【问题讨论】:

  • 感谢您的回答,我不想要像 404.html 或 something.html 这样的特定页面。我正在寻找更通用的服务器或未找到(没有 html)。谢谢你!

标签: .htaccess redirect dns web-hosting


【解决方案1】:

你可以这样做:

更新

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^domainb\.com$ [NC]
RewriteRule .*  - [R=404]

您也可以尝试一般禁止错误,如下所示:

order allow,deny
deny from b.com
allow from all

【讨论】:

    【解决方案2】:

    通过httpd.conf启用mod_rewrite和.htaccess,然后把这段代码放到你.htaccessDOCUMENT_ROOT目录下:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_REFERER} b\.com [NC]
    RewriteRule ^ /404.html [R=404,L]
    

    这将检查流量是否来自b.com,如果是,则将所有请求重定向到通用404.html 页面。

    【讨论】:

      【解决方案3】:

      我是如何将这段代码放在 htaccess 文件中的:

      <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_URI} !^/index.html$
      RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
      RewriteRule .* /index.html [L,R=302]
      </IfModule>
      

      将请求发送到 index.html 文件。然后使用html中的刷新功能将文件重定向到所需的域:

      index.html
      
      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">
      <html>
       <head>
         <title></title>
      <META http-equiv="refresh" content="0;URL=https://www.mydomain.co.uk/">
       </head>
       <body>
      
      
       </body>
      </html>
      

      【讨论】:

        猜你喜欢
        • 2018-03-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-08
        • 1970-01-01
        • 2016-04-20
        • 1970-01-01
        相关资源
        最近更新 更多