Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess将异常添加到404重定向到特定子目录_.htaccess_Redirect_Subdomain_Http Status Code 404 - Fatal编程技术网

.htaccess将异常添加到404重定向到特定子目录

.htaccess将异常添加到404重定向到特定子目录,.htaccess,redirect,subdomain,http-status-code-404,.htaccess,Redirect,Subdomain,Http Status Code 404,子目录是/addon/它存储我的子域(也称为addon域)的所有数据。 在这个子目录中,我还存储我的主域数据,我的主域是website.com RewriteEngine On RewriteCond %{HTTP_HOST} ^(www.)?website.com$ [NC] RewriteCond %{REQUEST_URI} ^/addon/(.*)$ RewriteRule ^(.*)$ - [L,R=404] 好的,这部分完成了,如果我输入website.co

子目录是/addon/它存储我的子域(也称为addon域)的所有数据。 在这个子目录中,我还存储我的主域数据,我的主域是website.com

RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www.)?website.com$ [NC]
    RewriteCond %{REQUEST_URI} ^/addon/(.*)$
    RewriteRule ^(.*)$ - [L,R=404]
好的,这部分完成了,如果我输入website.com/addon/mysecondwebsite-com,我会得到一个404。 如果我进入mysecondwebsite.com,我会看到website.com/addon/mysecondwebsite-com的内容

这太棒了,这正是我想要的

现在棘手的是,我已经设置了website.com来使用website.com/addon/website-com。无需告诉我如何为website.com配置/addon/website.com。我需要为配置为使用/addon/website com/的website.com禁用404,但我还需要确保如果我输入website.com/addon/website-com,该目录将返回404。*

我的重写条件提到,如果我在我的主域(website.com)上输入/addon/*我将返回404错误。这对于我的加载项域很好,因为它们使用/addon/而不是我的主域。但是我如何也阻止/addon/*但仍然使用我的主域

  • website.com=404/BAD(website.com/addon/website.com)
  • mysecondwebsite.com=200/Good(website.com/addon/mysecondwebsite.com)

  • website.com/addon/mysecondwebsite.com=404/Good

  • website.com/addon/website.com=404/Good

这是我的.htaccess文件,用于/public\u html/

# Part one block direct access to /addon/ folder
RewriteEngine On
        RewriteCond %{HTTP_HOST} ^(www.)?website.com$ [NC]
        RewriteCond %{REQUEST_URI} ^/addon/(.*)$
        RewriteRule ^(.*)$ - [L,R=404]

# Part two using /addon/website-com/ as website.com directory
        RewriteCond %{HTTP_HOST} ^(www.)?website.com$
        RewriteCond %{REQUEST_URI} !^/addon/website-com/
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ /addon/website-com/$1
        RewriteCond %{HTTP_HOST} ^(www.)?website.com$
        RewriteRule ^(/)?$ addon/website-com/index.php [L]

将404处理程序替换为以下内容:

ErrorDocument 404 /404.shtml

RewriteCond %{HTTP_HOST} ^(www\.)?website\.com$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+addon/ [NC]
RewriteRule (?!^404\.shtml$)^.*$ - [L,R=404,NC]

非常感谢。除了/addon/*的错误页面之外,这完全符合我的要求,它们不是我典型的错误页面。当有人访问website.com/addon/*…时,如何强制显示我的自定义404页面。。。这是我得到的404错误<代码>在此服务器上找不到请求的URL/addon/website com。此外,尝试使用ErrorDocument处理请求时遇到500内部服务器错误。感谢您的帮助:)我在您的.htaccess中没有看到任何ErrorDocument行。可能你需要这样的东西:
errordocument404/404.shtml
我需要离线,如果你还有其他问题,请留下评论,我将在几个小时后出席。ErrorDocument 404/404.shtml适用于除/addon/*之外的所有内容。这一定是某种块循环效应,会引发错误500。好的,明白了,请现在检查编辑的答案。