0

只是想知道是否有人会好心地查看我的 htaccess 代码并告诉我是否有任何看起来明显不正确的内容。我对这些东西了解不多。也不确定这些部件是否应该以不同的方式组织,或者是否有必要将“RewriteEngine on RewriteBase /”不止一次地放在那里?无论如何,这里是代码:

RewriteEngine  on 
RewriteBase    / 

RewriteRule ^(.+)\.shtml$   $1.html [R=301,L] 

redirect 301 /games.html http://www.slimekids.com/games/
redirect 301 /trailers.html http://www.slimekids.com/book-trailers/
redirect 301 /authors.html http://www.slimekids.com/authors/
redirect 301 /reference.html http://www.slimekids.com/reference/
redirect 301 /reviews.html http://www.slimekids.com/book-reviews/
redirect 301 /searches.html http://www.slimekids.com/search-engines/

RewriteEngine on
RewriteBase /

#if the domain is not www.slimekids.com
RewriteCond %{HTTP_HOST} !^www\.slimekids\.com$ [NC]
#redirect to www.slimekids.com
RewriteRule ^(.*)$ http://www.slimekids.com/$1 [L,R=301]

#leave this rule in place, but after the one above to handle the home page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/ 
RewriteRule ^index\.html$ http://www.slimekids.com/ [R=301,L] 

ErrorDocument 404 /404page.html

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##
4

2 回答 2

0

新的和改进的 htaccess。希望这一切现在看起来都很好。非常感谢。

RewriteEngine on
RewriteBase /

RewriteRule ^(.+)\.shtml$   $1.html [R=301,L] 

redirect 301 /games.html http://www.slimekids.com/games/
redirect 301 /trailers.html http://www.slimekids.com/book-trailers/
redirect 301 /authors.html http://www.slimekids.com/authors/
redirect 301 /reference.html http://www.slimekids.com/reference/
redirect 301 /reviews.html http://www.slimekids.com/book-reviews/
redirect 301 /searches.html http://www.slimekids.com/search-engines/

#if the domain is not www.slimekids.com
RewriteCond %{HTTP_HOST} !^www\.slimekids\.com$ [NC]
#redirect to www.slimekids.com
RewriteRule ^(.*)$ http://www.slimekids.com/$1 [L,R=301]

#leave this rule in place, but after the one above to handle the home page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/ 
RewriteRule ^(.*)index\.html$ http://www.slimekids.com/$1 [R=301,L]

ErrorDocument 404 /404page.html

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 month"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##
于 2012-05-31T04:31:08.973 回答
0

代码看起来不错。

你是正确的RewriteEngine onRewriteBase /不需要重复。

我注意到 exprires 离未来还很远。例如图像在一年后过期。可能是您的代码在发生变化时使用了某种缓存清除。

我可能会稍微改变index.html从 url 中删除部分的行,以在子文件夹(例如/games/index.html)上工作,而不仅仅是根(/index.html

#leave this rule in place, but after the one above to handle the home page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/ 
RewriteRule ^(.*)index\.html$ http://www.slimekids.com/$1 [R=301,L] 
于 2012-05-30T10:05:48.050 回答