0

我要创建一个新网站;内容归类为文章;标签和类别我有文件夹 1 和文件夹 2,它们是远程 Web 服务器上的文件夹;这两个文件夹中的每一个都可能包含 HTML 文件

我希望所有浏览我网站的人

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 点,非常感谢

4

1 回答 1

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
于 2012-09-04T14:19:25.823 回答