Apache 404网址无效
问题描述:
我的公司网站存在一些问题。我的同事离开了.htaccess
文件_control
目录里面是这样的:Apache 404网址无效
# 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已经在这里回答了第一部分问题:https://stackoverflow.com/a/26013322/1933380并且我能够获得虚拟目录的工作。我仍然遇到404页面的问题。我错过了什么或者犯了错误吗?
答
你现在在做什么,是告诉网络服务器在另一个文件夹(_control)中查找所有不存在的页面和目录。如果你想解决这个本没有给出错字的,不存在的网页等的解决方案,你可以使用:
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页和(对于例如)根据数据库搜索或其他方式给出可能的替代方案。然后您可以使用$_GET['file']
来显示原始文件名。
+0
它没有使用我创建的错误文件,所以我最终在代码下使用了这个代码:'ErrorDocument 404/site/error.php',它现在可以正常工作。 – vDog 2014-09-25 00:11:29
我没有在您的.htaccess中看到任何'ErrorDocument 404'行。另外你的规则是说任何不存在的文件或目录都会将它发送到'site/$ 1',所以显然会影响404的处理。 – anubhava 2014-09-24 11:47:55