.htaccess文件中的额外行

时间:2014-02-19 19:41:39

标签: apache .htaccess mod-rewrite redirect

我想清理任何不必要的代码行的.htaccess文件。这就是我现在所拥有的:

Options +FollowSymLinks   
RewriteEngine on   
RewriteCond %{HTTP_HOST} !^www.aicmillworks.com$ [NC]   
RewriteRule ^(.*)$ http://www.aicmillworks.com/$1 [L,R=301]   
ReWriteRule ^home$ / [R=301,L]   
RewriteCond %{THE_REQUEST} \ /([^\?\ .]*)\.(?:\?|\ |$)  
RewriteRule ^ /%1 [L,R=301]   
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*    
RewriteRule .* – [F,L]

“RewriteEngine on”之后的两行用于将非www重定向到www。之后的所有线路,我不确定他们做了什么或为什么他们在那里。删除它们会更好吗?或者它们对我的网站有什么重要意义?他们做了什么?

1 个答案:

答案 0 :(得分:1)

我不完全确定第三个人做了什么,但其余的规则将在下面解释。

# Redirect: prepend www. if the domain does not start with www.
RewriteCond %{HTTP_HOST} !^www.aicmillworks.com$ [NC]
RewriteRule ^(.*)$ http://www.aicmillworks.com/$1 [L,R=301]

# Redirect: /home to /
ReWriteRule ^home$ / [R=301,L] 

# Redirect: strip the file format. So /test.html redirects to /test
# I tried testing this on your site, but it didn't work, so I'm not sure if you have this rule enabled or not.
RewriteCond %{THE_REQUEST} \ /([^\?\ .]*)\.(?:\?|\ |$)
RewriteRule ^ /%1 [L,R=301]

# Block libwww-perl from your website. Usually for blocking bots
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]

至于“删除它们会不会更好或者它们对我的网站有什么影响?”,它们肯定不会损害您的网站,所以您也可以离开它们。