Apache 404 url不工作

Apache 404 url不工作,apache,.htaccess,Apache,.htaccess,我对我们公司的网站有一些问题。我的同事将.htaccess文件放在\u控件目录中,如下所示: # Virtual site directory # # This script lets us make use of default # versions of files used in a typical site. # When a request on the site is made for a file # that doesn't exist, instead of a 404 we

我对我们公司的网站有一些问题。我的同事将
.htaccess
文件放在
\u控件
目录中,如下所示:

# Virtual site directory
#
# This script lets us make use of default
# versions of files used in a typical site.
# When a request on the site is made for a file 
# that doesn't exist, instead of a 404 we rewrite
# the path to /_control/site/
#
# Any file in the directory this script is in will 
# take precedence over this script, so this script
# only comes into play if the file does not exist.

# First, set up URL rewriting
Options +FollowSymLinks
RewriteEngine On

# Add trailing slash for directories
# TODO: fix if site not in root dir (e.g. DEV server)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !.+\.(php|js|css|gif|jpg|jpeg|png)$ [NC]
RewriteCond %{REQUEST_URI} !.*/$
RewriteRule ^(.*)$ /$1/ [L,R=301]

# This Apache mod_rewrite rule checks to see
# if the requested file exists, if it doesn't
# then we rewrite to the respective site location.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^.*/_control/(admin|common).*$
RewriteCond %{REQUEST_FILENAME} !^.*/_control/site/.*$
RewriteRule ^(.*)$ site/$1 [L]
我的应用程序的结构如下所示:


一切正常,但大约一周前,我们的mysite.com/admin和404页面开始重定向到托管公司的网站。DaveG已经回答了问题的第一部分:我能够让虚拟目录正常工作。我仍然有404页的问题。我是否遗漏了什么或犯了错误?

您现在所做的是告诉Web服务器在另一个文件夹(\u控件)中查找所有不存在的页面和目录。这并不能解决打字错误、不存在的页面等问题。如果您想解决此问题,可以使用:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^.*/_control/(admin|common).*$
RewriteCond %{REQUEST_FILENAME} !^.*/_control/site/.*$
RewriteRule ^(.*)$ site/errhandler.php?file=$1 [L]

并创建一个名为
errhandler.php
的文件,该文件显示一个自定义404页面,并(例如)基于数据库搜索或其他方式给出可能的替代方案。然后可以使用
$\u GET['file']
显示原始文件名。

我在.htaccess中没有看到任何
错误文档404
行。另外,您的规则是,任何不存在的文件或目录都将其发送到
site/$1
,这显然会影响404处理。它没有使用我创建的错误文件,因此我最终在我的代码下面使用了以下代码:
ErrorDocument 404/site/error.php
,现在可以正常工作了。