使用重定向从 URL 中删除 .html [英] Remove .html from URLs with a redirect

查看:27
本文介绍了使用重定向从 URL 中删除 .html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个网站,不幸的是所有的 URL 都有 .html 后缀,它是一个 Magento 安装,Magento 允许你在 CMS 上更改它,但不幸的是,所有这些 URL 都带有 .html 后缀在谷歌有很好的排名.我们需要重定向到非.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

所以 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...

干杯!

这篇关于使用重定向从 URL 中删除 .html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆