.htaccess URL重写-即使在.htaccess文件中存在URL重写规则,页面也会用URL打开,而不需要URL重



我需要关于网站图像库URL重写的帮助。

这是一个问题,我需要改变主机,所以我把网站转移到另一个服务器,有问题,因为当它被转移到新的服务器网站工作没有url重写,即使。htaccess文件存在。几天后问题解决了,我的链接看起来又不错了。但是,当。htaccess中的URL重写不工作时,搜索引擎及时抓取了我的网站,所以相同的页面以两种方式索引,有漂亮的URL和没有URL重写。就像我说的链接现在是可以的,但是在搜索引擎的数据库中有很多结果仍然是这样打开的。

CMS图片库生成的正常精细链接如下:

http://www.mysite.net/Category/Subcategory/Item-name.html

但是,在搜索引擎数据库中,仍然有很多结果没有重写URL,链接如下:

http://www.mysite.net/show.php?cat=Category&sub_cat=Subcategory&img=Item-name

的例子:

如果有人试图打开页面,它将以两种方式打开,实际上你可以看到同一个页面打开:

http://www.mysite.net/Category/Subcategory/Item-name.html

http://www.mysite.net/show.php?cat=Category&sub_cat=Subcategory&img=Item-name

你能帮我一些SEO友好的URL重定向规则吗

这是我的。htaccess文件中与图片库相关的一部分。


Options +FollowSymLinks
RewriteEngine On
RewriteBase /
######## Begin - URL rewriting for image gallery ########
## For showig category of item
RewriteRule ^(.*)/$ showcat.php?cat=$1 [L]
## For showig subcategory of item
RewriteRule ^(.*)/(.*)/$ showcat.php?cat=$1&subcat=$2 [L]
## For showig item
RewriteRule ^(.*)/(.*)/(.*).html$ show.php?cat=$1&sub_cat=$2&img=$3 [L]
## For latest items
RewriteRule ^latest-page-(.*)/$ latest.php?page=$1 [L]
## For top rated items
RewriteRule ^top/page/(.*)/$ top.php?page=$1 [L]
## For show most rated - most clicked - most downloaded and most searched items
RewriteRule ^most-rated.html$ showmost.php?type=1 [L]
RewriteRule ^most-clicked.html$ showmost.php?type=2 [L]
RewriteRule ^most-downloaded.html$ showmost.php?type=3 [L]
RewriteRule ^most-Searched.html$ showmost.php?type=4 [L]
######## Begin - URL rewriting for image gallery ########


然而,我不能得到这样的链接:

http://www.mysite.net/Category/Subcategory/Item-name.html

我尝试了你的解决方案,像这样:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
######## Begin - URL rewriting for image gallery ########
## For showig category of item
RewriteRule ^(.*)/$ showcat.php?cat=$1 [L]
## For showig subcategory of item
RewriteRule ^(.*)/(.*)/$ showcat.php?cat=$1&subcat=$2 [L]
## For showig item
RewriteRule ^(.*)/(.*)/(.*).html$ show.php?cat=$1&sub_cat=$2&img=$3 [L]
## this section should be inserted just after the showing item rule above
#if the query string has cat, sub_cat and Img
RewriteCond %{QUERY_STRING} ^cat=(.+)&sub_cat=(.+)&img=(.+)$ [NC]
#and it is for resource show.php, then 301 redirect to Keyword rich URL
RewriteRule ^show.php$ http://www.mysite.net/%1/%2/%3.html [NC,L,R=301]
## For latest items
RewriteRule ^latest-page-(.*)/$ latest.php?page=$1 [L]
## For top rated items
RewriteRule ^top/page/(.*)/$ top.php?page=$1 [L]
## For show most rated - most clicked - most downloaded and most searched items
RewriteRule ^most-rated.html$ showmost.php?type=1 [L]
RewriteRule ^most-clicked.html$ showmost.php?type=2 [L]
RewriteRule ^most-downloaded.html$ showmost.php?type=3 [L]
RewriteRule ^most-Searched.html$ showmost.php?type=4 [L]
######## End - URL rewriting for image gallery ########

现在,我可以用这个正常的URL访问同一个页面:

http://www.mysite.net/Category/Subcategory/Item-name.html

我猜是因为新的URL重定向规则现在URL是这样的

http://www.mysite.net/show.php?cat=Category&sub_cat=Subcategory&img=Item-name

被重定向为:

http://www.mysite.net/Item-name.html?cat=Category&sub_cat=Subcategory&img=Item-name

但是,你肯定知道我只希望这个URL:

http://www.mysite.net/Category/Subcategory/Item-name.html

如果搜索引擎用旧的url索引了你的网站,而你已经把它们改成了富含关键字的url,那么让他们知道使用新url的正确方法是301重定向旧url到新url的请求。

编辑当前的。htaccess文件,并在显示项规则后面放置部分,将旧的url重定向到新的url,如下所示。

## For showig item
RewriteRule ^(.*)/(.*)/(.*).html$ show.php?cat=$1&sub_cat=$2&img=$3&rewrite=true [L]
## this section should be inserted just after the showing item rule above
#if the query string has cat, sub_cat and Img
RewriteCond %{QUERY_STRING} ^cat=(.+)&sub_cat=(.+)&img=(.+)$ [NC]
#and it is for resource show.php, then 301 redirect to Keyword rich URL
RewriteRule ^show.php$ http://www.mysite.net/%1/%2/%3.html? [NC,L,R=301]

最新更新