.htaccess重定向以避免404

时间:2012-10-01 15:08:52

标签: .htaccess mod-rewrite

我最近在CMS中进行了更改,导致Google网站管理员出现大量404错误。目前404找不到网址

http://pukhtoogle.com/gallery/postcard.img707.htm

工作网址为

http://pukhtoogle.com/gallery/img707.htm

我想通过.htaccess从网址中排除明信片,请提示更换一行,以下代码显示我现有的文件。

RewriteEngine On 

#RewriteBase /
RewriteRule ^sitemap.xml$ google.php
RewriteRule ^cat-(.*)-([0-9]+)\.htm$ categories.php?cat_id=$2&%{QUERY_STRING}
RewriteRule ^cat\.htm$ categories.php?%{QUERY_STRING}

#Mod_bmollet : Image name in URL
RewriteRule ^img-(.*)-([0-9]+)\.htm$ details.php?image_id=$2&%{QUERY_STRING}
RewriteRule ^img([0-9]+)\.search.htm$ details.php?image_id=$1&%{QUERY_STRING}
RewriteRule ^img([0-9]+)\.lightbox.htm$ details.php?image_id=$1&%{QUERY_STRING}
RewriteRule ^img([0-9]+)\.htm$ details.php?image_id=$1&%{QUERY_STRING}
RewriteRule ^img([0-9]+)\.([a-zA-Z0-9]+)\.htm$ details.php?image_id=$1&mode=$2&%        {QUERY_STRING}


#Mod_bmollet : This is to make search function work ( redirect links from search results )
RewriteRule ^search\.htm$ search.php?%{QUERY_STRING}
RewriteRule ^search\.([0-9]+)\.htm$ search.php?page=$1&%{QUERY_STRING}
RewriteRule ^lightbox\.htm$ lightbox.php?%{QUERY_STRING}
RewriteRule ^lightbox\.([0-9]+)\.htm$ lightbox.php?page=$1&%{QUERY_STRING}

1 个答案:

答案 0 :(得分:1)

在htaccess文件的RewriteEngine On下,添加:

RewriteRule ^gallery/postcard\.(.*)$ /gallery/$1 [L,R=301]

编辑:在您的网站上玩了一会儿之后,看起来所有这些规则实际上都在gallery目录中,这将是非常宝贵的信息,可以从启动。

因此,您必须省略正则表达式的gallery/部分:

RewriteRule ^postcard\.(.*)$ /gallery/$1 [L,R=301]

RewriteRule ^postcard\.(.*)$ http://pukhtoogle.com/gallery/$1 [L,R=301]