2014-09-24 79 views
-2

我的公司網站存在一些問題。我的同事離開了.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] 

我的應用程序的結構是這樣的:

enter image description here

一切都在一個星期前工作正常,但對我們的mysite的。 com/admin和404頁面開始重定向到託管公司的網站。 DaveG已經在這裏回答了第一部分問題:https://stackoverflow.com/a/26013322/1933380並且我能夠獲得虛擬目錄的工作。我仍然遇到404頁面的問題。我錯過了什麼或者犯了錯誤嗎?

+1

我沒有在您的.htaccess中看到任何'ErrorDocument 404'行。另外你的規則是說任何不存在的文件或目錄都會將它發送到'site/$ 1',所以顯然會影響404的處理。 – anubhava 2014-09-24 11:47:55

回答

1

你現在在做什麼,是告訴網絡服務器在另一個文件夾(_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