我需要一个规则,将增加一个.html扩展每当有'不是'斜线。
I need a rule that will add an .html extension whenever there is 'not' a trailing slash.
一个新的客户最近改变了电子商务脚本和新版本的搜索引擎优化的处理不同,改变了他们所有的16000产品链接。这是没有抓到之前,该网站正在重新建立索引,所以我们需要重定向旧到新的..
A new client recently changed ecommerce scripts and the new version handles SEO differently and changed all of their 16,000+ product links. This was not caught prior to the site being re-indexed so we need to redirect the old to the new..
曾经有过这样的链接全部产品 domain.com/category/productname 但现在 domain.com/category/productname.html
All products used to have links like this domain.com/category/productname but are now domain.com/category/productname.html
分类链接并没有改变,所有的都是这样的 domain.com/category/(带斜杠)
Category links did not change and all are like this domain.com/category/ (with trailing slash)
推荐答案
从@大卫 - wolever答案重定向不以html结束一切(或根),以相同的URL与添加的扩展名为.html,意义它附加一个.html扩展到像CSS和JavaScript的文件,例如:它会重定向/style.css到/style.css.html这是不太可能你想要什么。它也有后的空间!性格这可能会导致@greggles 500S
The answer from @david-wolever redirects everything that does not end in .html (or the root) to the same URL with an added .html extension, meaning it appends a .html extension to things like CSS and JavaScripts files, e.g. it will redirect /style.css to /style.css.html which is not likely what you want. It also has the spaces after ! character which will likely caused @greggles 500s
这重定向不以点和3个或4个字母数字字符结尾的URL:
This redirects URLs which do not end in a dot followed by 3 or 4 alphanumeric characters:
RewriteEngine On
RewriteCond %{REQUEST_URI} !.[a-zA-Z0-9]{3,4}
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1.html
或为更细的颗粒控制,白名单,你不希望的.html追加到如扩展
Or for finer grain control, whitelist the extensions you do not want .html appended to e.g.
RewriteCond %{REQUEST_URI} !.(html|css|js|less|jpg|png|gif)$
相关推荐
最新文章