我已经为这个问题苦苦挣扎了一个星期。
我的网站根目录是这样的:
index.html
page.html
subfolder/index.html
subfolder/page.html
我已经阅读了大量的文章来做这三件事。实际上,我可以单独进行操作,但是无法确定如何将它们组合在一起!
.html
扩展名index.html
在子文件夹中查找URL
(例如www.domain.com/subfolder/page.html
,www.domain.com/subfolder/page/
这将是超级如果在写入www.domain.com/page.html
了URL
会自动更改为www.domain.com/page/
先感谢您!
我目前的htaccess:
RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ $1.html [NC,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
用此代码替换所有代码块:
DirectoryIndex index.html
RewriteEngine on
# redirect file.html to /file/
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html\s [NC]
RewriteRule ^ /%1/ [R=302,NE,L]
# added .html extension to /file by checking presence of file.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句