對不起,如果標題混淆。.htaccess - 子文件夾到子文件夾=子文件夾404
我在本地機器上設置了一個虛擬主機。我已將http://dev
設置爲映射到我的/htdocs/dev
文件夾。從dnsmasq和.htaccess的一些幫助,我已經設置它,以便它將子域.dev
映射到/htdocs/dev
內的文件夾。當我嘗試訪問時,這一切都很完美,例如,http://dev/file1.html
或http://folder.dev/file2.html
。訪問子文件夾時發生問題。如果我嘗試訪問http://folder.dev/subfolder/
或http://folder.dev/subfolder/file3.html
,我會得到404 Object not found
。
我想它可以用.htaccess解決,但我沒有做到,儘管我嘗試了。這裏是我的/htdocs/dev/.htaccess
看起來像:
# Default index file
DirectoryIndex index.php
# Interpret .html files as .php scripts
AddHandler php5-script .php .html
# Redirect subdomains to their respective folders
RewriteEngine on
RewriteBase/
RewriteCond %{HTTP_HOST} !^www\.dev$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.dev$ [NC]
RewriteRule !^([a-z0-9-]+)($|/) /%2%{REQUEST_URI} [PT,L]
我應該提到的是,如果我嘗試訪問http://dev/folder/subfolder/file3.html
,不存在任何問題。
如何設置地址如http://folder.dev/subfolder/
指向/htdocs/dev/folder/subfolder
?
嗨@JonLin感謝您的回覆。我需要離開還是刪除這兩行:'RewriteEngine on'和'RewriteBase /' –
@ТомицаКораћLeave them –
So @jon,我刪除了我的.htaccess中的最後三行並添加了行。不幸的是,它不工作。 'http:// folder.dev'獲得'500內部服務器錯誤'加''另外,嘗試使用ErrorDocument處理請求時遇到500內部服務器錯誤錯誤。 –