2012-09-04 46 views
0

我正在創建一個新的網站;內容被分類爲文章;標籤和類別 我有folder1和folder2這是遠程Web服務器上的文件夾;每一個這兩個文件夾中可能包含HTML文件強制url模式

我想,大家誰在瀏覽我的網站

1-When he types 
    www.domin.com/folder1/ -->dispaly the index.html file under the folder1 folder 

2-When he types www.domin.com/folder1 --> error 

3-When he types 
www.domain.com/folder1/file1/ 
      dispaly the /folder1/file1.html file 

4-When he types 
    www.domain.com/folder/file.html or 
    www.domain.com/folder/file 
      dispaly an eror: such file does not exist 

其實,我做的是兩點:1,3 以下.htacces文件內容(下遠程Web服務器上的public_html文件夾)

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.html -f 
RewriteRule ^([^/]+)/$ $1.html 

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.]+\.php(\?[^\ ]*)?\ HTTP/ 
RewriteRule ^(([^/]+/)*[^.]+)\.php$ http://www.domain.com/$1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ 
RewriteRule (.*)$ http://www.domain.com/$1/ [R=301,L] 



#DirectorySlash On 
#RewriteEngine On 
#RewriteCond %{REQUEST_FILENAME} !-f 
#RewriteRule ^([^\.]+)$ $1.html [NC,L] 
#RewriteRule ^([^\.]+)$ $1.htm [NC,L] 
#RewriteRule ^([^\.]+)$ $1.php [NC,L] 

我需要幫助修改我的.htaccess文件,以便爲與點2一致,和4 非常感謝

回答

1

試試這個應該支持4條規則:

RewriteEngine on 
RewriteBase/

RewriteRule ^([^/]+)/$ $1/index.html [QSA,L] # rule 1 
RewriteRule ^([^/]+)/([^/]+)/$ $1/$2.html [QSA,L] # rule 3 
RewriteRule ^[^/]+(/[^/]+(\.html)?)?$ doesnotexists.html [L] # rule 2 and 4 
+0

這不起作用 – Oumdaa