【发布时间】:2019-03-07 00:28:39
【问题描述】:
我的.htaccess 重定向规则有问题。
我需要将以.html 结尾的页面重定向到以斜线结尾的页面。/about-us.html 到/about-us/
但也有一些页面我需要重定向到没有 .html 的特定页面,例如 /gallery/first-gallery/this-is-the-gallery.html 到 /gallery/new/
问题是我的规则不能很好地协同工作,似乎重定向 .html 页面的规则忽略了所有其他规则。
这就是我的.htaccess 的样子
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/?(.*).(html)$ /$1 [R=301,L]
Redirect 301 /about-us/photo-gallery/17577-album-mca-corona-clay-tile-roof-princeton-texas/131173-58e29f485064eprinceton-texas-roofing-services-1.html /about-us/photo-gallery/17577-album-mca-corona-clay-tile-roof-princeton-texas/
Redirect 301 /about-us/photo-gallery/17577-album-mca-corona-clay-tile-roof-princeton-texas/131174-58e2a063b8b06princeton-texas-roofing-services-2.html /about-us/photo-gallery/17577-album-mca-corona-clay-tile-roof-princeton-texas/
#Many other 301 rules below
</IfModule>
所以当我在浏览器中输入domain.com/about-us/photo-gallery/17577-album-mca-corona-clay-tile-roof-princeton-texas/131173-58e29f485064eprinceton-texas-roofing-services-1.html
时,它会重定向到 domain.com/about-us/photo-gallery/17577-album-mca-corona-clay-tile-roof-princeton-texas/131173-58e29f485064eprinceton-texas-roofing-services-1
我需要这个特定的重定向来重定向到 /about-us/photo-gallery/17577-album-mca-corona-clay-tile-roof-princeton-texas/
我尝试将RewriteRule ^/?(.*).(html)$ /$1 [R=301,L] 移到底部,希望上面的规则会首先处理,但这不起作用。
我可以做些什么来根据需要完成这项工作?
【问题讨论】: