使用重定向从网址中删除.html [英] Remove .html from URLs with a redirect
问题描述
我们有一个网站,不幸的是,所有URL都带有.html
后缀,它是Magento的安装,Magento允许您在CMS上进行更改,但是不幸的是,所有这些带有.html
后缀的URL都有很好的排名在Google中.我们需要重定向到非.html
.
We have a website, unfortunately all the URLs have the .html
suffix, its a Magento installation, Magento allows you to change this on the CMS, but again, unfortunately all this URLs with .html
suffix have a good ranking in Google. We need to redirect to non .html
.
因此,请考虑以下情形,我们正在从头开始重建此站点,因此我们在新站点上具有相同的url,但没有.html后缀.
So, consider the following scenario, we are rebuilding this site from scratch, so we have the same urls on the new site but without the .html suffix.
- 现在是:
www.example.de/cool-shoes.html
- 将会是:
www.example.de/cool-shoes
- Now is:
www.example.de/cool-shoes.html
- Will be:
www.example.de/cool-shoes
所以www.example.de/cool-shoes.html
将不再存在,并且我一直尝试使用 .htaccess 进行重定向,但是没有运气.
So www.example.de/cool-shoes.html
will not exist anymore, and I've been trying a redirect with the .htaccess with no luck.
到目前为止,我已经尝试过:
I've tried so far:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule (.*)index\.html$ /$1 [R=301,L]
和:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
但这似乎不起作用...有什么主意吗?
but it doesn't seem to work...any ideas?
推荐答案
好的,在进行了一些研究之后,由于未能通过重写规则实现这一点,因此以下代码行起作用了:
Ok so, after some research, and failing to achieve this with a rewrite rule, the following line of code worked:
redirectMatch 301 ^(.*)\.html $1
这对于删除任何url扩展名并避免链接断开非常有用,希望将来对某人有所帮助...
This is quite usefull to remove any url extension and avoid broken links, hopefully helps someone in the future...
欢呼!
这篇关于使用重定向从网址中删除.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!