强制网址模式

时间:2012-09-04 11:19:12

标签: .htaccess url-rewriting

我是关于创建一个新网站;内容被归类为文章;标签和类别 我有folder1和folder2,它们是远程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点 非常感谢

1 个答案:

答案 0 :(得分: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