[英]How do I redirect all requests that does NOT contain certain string to 400 using nginx
[英]How do I redirect all requests for .html files to directories with respective names?
第一个问题非常感谢恩典! 我有一个站点,过去有成千上万个.html文件,现在这些目录现在是目录内的index.html文件。 例如, file1.html
已成/file1/
( /file1/index.html
)。 我不想将inode花费在单个文件上,所以我希望可以在htaccess文件中进行。 我想它必须测试目录的存在,实际上这是不可能的,对吧?
将此添加到您的Web根目录/
.htaccess
中
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/$1 -d # Dir exists?
RewriteRule ^(.*)\.html$ /$1/ [R=301,L]
将其放在包含所有目录的目录中:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^\/(.*)\.html$
RewriteRule .* /%1/ [R=301,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.