首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >请参阅htaccess代码

请参阅htaccess代码
EN

Stack Overflow用户
提问于 2012-05-30 07:29:38
回答 2查看 112关注 0票数 0

我想知道是否有人愿意看一下我的htaccess代码,并告诉我有没有什么明显不正确的地方。我对这些东西所知不多。也不确定这些部分是否应该以不同的方式组织,或者是否有必要多次在其中放置"RewriteEngine on RewriteBase /“?不管怎样,下面是代码:

代码语言:javascript
复制
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 ##
EN

回答 2

Stack Overflow用户

发布于 2012-05-30 18:05:48

代码看起来没问题。

RewriteEngine onRewriteBase /不需要重复,这一点您是正确的。

我注意到实验是相当遥远的未来。例如,图像在一年后过期。当某些东西发生变化时,您的代码可能会使用某种类型的缓存破坏。

我可能会稍微修改从url中删除index.html部分的代码行,使其也适用于子文件夹(例如/games/index.html),而不仅仅是根文件夹(/index.html)

代码语言:javascript
复制
#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] 
票数 0
EN

Stack Overflow用户

发布于 2012-05-31 12:31:09

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

代码语言:javascript
复制
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 ##
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10808120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档