0
基本上,我有這樣的目錄設置:.htaccess |打開文件不目錄
/.htaccess
/home.php
/office.php
/office/tutorials.php
和.htaccess文件是這樣的:
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
order deny,allow
# setup
DirectoryIndex /home.php
ErrorDocument 403 /err403.php
ErrorDocument 404 /err404.php
# remove trailing slash
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule^%1 [R=301,L]
# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
現在下面發生的事情。 當我打電話給「www.domain.com/home」時,它完美地工作。 但是當我嘗試打電話給「www.domain.com/office」時,我總是得到home.php頁面而沒有樣式,它顯示我在「www.domain.com/office/」,所以我猜名爲office的目錄。
我試着重命名辦公室/目錄,然後office.php文件再次完美工作,但我需要的目錄命名爲相同的文件,所以該URI看起來不錯,乾淨,並建立在彼此像這個:
www.domain.com/office (own page)
www.domain.com/office/tutorials (own page)
在此先感謝!
太棒了!這解決了大部分問題,但是現在它在URI的末尾添加了一個斜槓,當存在一個同名的目錄時... –
如果您希望將「刪除尾部斜線」規則應用於目錄,則從該規則中刪除相同的RewriteCond。 –
我嘗試過,但後來我得到一個重定向錯誤... –