移动目录位置时找不到404 url(htaccess)


404 url not found when directory location moved (htaccess)

我有这个文档根/var/www/example,然后在这个目录中我有一个文件test.php,还有我的另一个项目,所以项目的结构看起来像这个

/var/www/example

├── .htaccess (Obs)
├── classes  
├── config
├── controllers
├── public
│   ├── admin
│   │   └── index.php 
│   ├── css
│   ├── index.php
│   └── js
├── test.php (Obs! not managed by .htaccess)
└── views

.htaccess

Options +FollowSymLinks
AddDefaultCharset UTF-8 
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^admin[/]?$ /example/admin/login [redirect]
RewriteRule ^admin/([a-zA-Z]+)/?([a-zA-Z0-9/]*)$ public/admin/index.php?page=$1&query=$2 [L]
RewriteRule ^([a-zA-Z]+)/?([a-zA-Z0-9/]*)$ public/index.php?page=$1&query=$2 [L]

我最近将该项目从在localhost上运行的MAMP服务器转移到了域驱动的服务器。当我尝试时

test.php

文件,它工作和echo "It works"的意图,但当我尝试运行我的网站,它不。

错误日志

 [Mon Jul 29 18:02:52 2013] [error] [client 83.248.93.217] script '/var/www/example/index.php' not found or unable to stat
 [Mon Jul 29 18:02:52 2013] [error] [client 83.248.93.217] File does not exist:     /var/www/favicon.ico
 [Mon Jul 29 18:03:02 2013] [error] [client 83.248.93.217] File does not exist: /var/www/example/bordsoversikt
 [Mon Jul 29 18:03:02 2013] [error] [client 83.248.93.217] File does not exist: /var/www/favicon.ico

我的控制器通过名称将一些网站映射到相应的文件,如

client_router所有调用都作为htaccess通过index.php,然后到达路由器。。。

public function initialize_routes() {
$this->routes = array(
    "bordsoversikt" => "page_table_overview",
    "bordsreservation" => "page_table_reservation",
    "reservationsprocess" => "script_reserve_form",
    "registrering" => "page_registration",
    "registreringsprocess" => "script_register_form",
    "lyckadregistrering" => "page_successfull_signup",
    "login" => "page_login",
    "logout" => "script_logout",
    "profil" => "page_home", 
    "klientlogin" => "script_login",
    "profil" => "page_profile",
    "sparaprofil" => "script_edit_profile_changes"
);

我认为我的htaccess文件可能有问题,我发布内容的原因,或者我的apache2.config文件可能有错误。但我对配置apache还很陌生,所以我不会尝试发布它的部分,因为我可能会发布不关键的部分。有人能帮帮我吗?谢谢

  1. 确保您的htaccess文件可由apache读取(例如,在linux上,chmod 644 /var/www/example/.htaccess

  2. 确保你的vhost或服务器配置允许覆盖:

    AllowOverride FileInfo
    

    或者更好的

    AllowOverride All        
    
  3. 不太可能,但在服务器/vhost-config文件中查找一个名为AccessFilename的命令。默认情况下,这通常是.htaccess,但如果不同,则需要将其更改为.htaccess将文件重命名为指令所说的任何名称。