2017-04-25 77 views
0

我使用的Apache 2.4.7DirectorySlash關閉不工作

這是我的虛擬主機的配置:

DocumentRoot /var/www/login 
ServerName login.mydomain.com 
<Directory "/var/www/login"> 
    allow from all 
    AllowOverride All 
    Options +Indexes 
    DirectoryIndex index.html index.php 
    DirectorySlash Off 
    Require all granted 
</Directory> 

在我/var/www/login目錄中,我有一個目錄名爲freeseat,並在那裏,有在index.php文件,因此它的全部位置/var/www/login/freeseat/index.php

當我嘗試通過以下鏈接(域替代)來訪問它,它重定向到以斜槓同一網址: http://login.mydomain.com/freeseat - >http://login.mydomain.com/freeseat/

爲什麼DirectorySlash Off不工作?我試圖把它放在.htaccess,但這也沒有幫助。

非常感謝您的幫助,

大衛

+0

它工作的很好,但沒有斜槓可能會在目錄列表中出現錯誤的鏈接。測試時禁用瀏覽器緩存。 – Deadooshka

回答

0

首先,你的虛擬主機不會,如果你不使用的指令工作。 這工作:

<VirtualHost *:80> 
    DocumentRoot /var/www/login 
    ServerName login.mydomain.com 
    <Directory "/var/www/login"> 
      Allow from all 
      AllowOverride All 
      Options +Indexes 
      DirectoryIndex index.html index.php 
      DirectorySlash Off 
      Require all granted 
    </Directory> 
ErrorLog /var/www/login/error.log 
</VirtualHost> 

要回答你的問題:DirectorySlash按預期工作。

另請參閱mod_dir的apache文檔,尤其是名爲「DirectorySlash」部分的「安全警告」紅色框。

提示:始終使用不可公開訪問的錯誤日誌來確定惡意根源。 :)


編輯#1:

我想我可能誤解了你的問題。您想通過http://login.mydomain.com/freeseat訪問/var/www/login/freeseat/index.php(無尾斜槓)。

然後,丟棄freeseat文件夾並使用的index.php作爲無功/網絡/登錄/ freeseat.php並創建在/var/www/login/.htaccess文件重寫規則(mod_rewrite的必須處於活動狀態):

RewriteEngine On 
RewriteRule ^freeseat$ freeseat.php 

此外,從您的虛擬主機配置下降

Options +Indexes 
DirectoryIndex index.html index.php 

。它不再需要了。

+0

感謝您回答我的問題。虛擬主機配置就像你說的(我沒有包括指令,但它是一樣的),但DirectorySlash不起作用。它保持重定向,並且在錯誤日誌中沒有任何內容顯示有任何錯誤 – david

+0

非常奇怪。對我而言,它按預期工作。 – Kapparina

+0

@編輯我想我誤解了你的問題。我要擴大我的答案。 – Kapparina

0

我做了一些更改設置,但我仍然面對的問題:

這是我的新設置:

<VirtualHost *:80> 
DocumentRoot /var/www/login 
ServerName login.mydomain.com 
<Directory "/var/www/login"> 
    allow from all 
    AllowOverride All 
    Require all granted 
</Directory> 
<Directory "/var/www/login/freeseat"> 
    allow from all 
    DirectoryIndex index.php 
    Options FollowSymLinks Indexes 
    DirectorySlash Off 
    AllowOverride All 
    Require all granted 
</Directory> 
</VirtualHost> 

2種情景:

  1. Options FollowSymLinks Indexes

我可以看到目錄列表,與inde X。列表中的PHP文件(不帶我去的話)

  • Options FollowSymLinks
  • 我得到這個錯誤在瀏覽器: You don't have permission to access /freeseat on this server.

    和這個錯誤在error.log中:

    Cannot serve directory /var/www/login/freeseat: No matching DirectoryIndex (none) found, and server-generated directory index forbidden by Options directive

    有一些缺失/錯的,但我不知道是什麼...