2012-09-22 95 views
0

對不起,如果標題混淆。.htaccess - 子文件夾到子文件夾=子文件夾404

我在本地機器上設置了一個虛擬主機。我已將http://dev設置爲映射到我的/htdocs/dev文件夾。從dnsmasq.htaccess的一些幫助,我已經設置它,以便它將子域.dev映射到/htdocs/dev內的文件夾。當我嘗試訪問時,這一切都很完美,例如,http://dev/file1.htmlhttp://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

回答

0

首先,感謝送給@JonLin讓我有這個提示。

我已經成功與此.htaccess文件來解決這個問題:

# Ordered list of index files, if none exist, show directory listing 
    DirectoryIndex index.php index.html 

# Interpret .html files as .php scripts 
    AddHandler php5-script .php .html 

# Redirect subdirectories to their respective folders 
    RewriteEngine on 
    Options +FollowSymlinks 
    RewriteBase/

    RewriteCond %{HTTP_HOST} !^www\.dev$ [NC] 
    RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.dev(.*)?$ [NC] 
    RewriteRule !^%2\.dev%3?/$ http://dev/%2%{REQUEST_URI}/ [P] 

怎麼看的改寫部確實是需要一個URL中的http://folder.dev/subfolder形式和它指向到/ dev /文件夾/子文件夾,而保存網址。它可以使用或不使用www。

0

試着改變你的規則:

RewriteCond %{HTTP_HOST} !^www\.dev$ [NC] 
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.dev$ [NC] 
RewriteCond %{DOCUMENT_ROOT}/%2{REQUEST_URI} -f [OR] 
RewriteCond %{DOCUMENT_ROOT}/%2{REQUEST_URI} -d 
RewriteRule^/%2%{REQUEST_URI} [PT,L] 
+0

嗨@JonLin感謝您的回覆。我需要離開還是刪除這兩行:'RewriteEngine on'和'RewriteBase /' –

+0

@ТомицаКораћLeave them –

+0

So @jon,我刪除了我的.htaccess中的最後三行並添加了行。不幸的是,它不工作。 'http:// folder.dev'獲得'500內部服務器錯誤'加''另外,嘗試使用ErrorDocument處理請求時遇到500內部服務器錯誤錯誤。 –