使用重定向从URL中删除.html

Kaß*_*ßta 7 apache .htaccess url-rewriting magento

我们有一个网站,不幸的是所有的URL都有.html后缀,它是Magento的安装,Magento允许你在CMS上更改它,但不幸的是,所有带有.html后缀的URL 在Google中都有很好的排名.我们需要重定向到非.html.

因此,请考虑以下情况,我们正在从头开始重建此站点,因此我们在新站点上具有相同的URL但没有.html后缀.

  • 现在是: www.example.de/cool-shoes.html
  • 将会: www.example.de/cool-shoes

因此 www.example.de/cool-shoes.html将不再存在,我一直在尝试使用.htaccess重定向而没有运气.

我到目前为止尝试过:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule (.*)index\.html$ /$1 [R=301,L] 
Run Code Online (Sandbox Code Playgroud)

和:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Run Code Online (Sandbox Code Playgroud)

但它似乎没有用......任何想法?

Kaß*_*ßta 10

好的,经过一些研究,并且未能通过重写规则实现这一点,以下代码行有效:

redirectMatch 301 ^(.*)\.html $1
Run Code Online (Sandbox Code Playgroud)

这对于删除任何网址扩展并避免断开链接非常有用,希望将来帮助某人...

干杯!


Jos*_*era 8

这将重写网址,如http://example.com/page.html - > http://example.com/page

# Remove .html from url
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Run Code Online (Sandbox Code Playgroud)