我一直尝试以下各种变体而没有成功:
Redirect permanent /([0-9]+)/([0-9]+)/(.?).html http://example.com/($3)
似乎没有效果。我也尝试过重写类似的缺乏结果。
我希望所有链接类似于:http://example.com/2002/10/some-long-title.html 将浏览器和蜘蛛重定向到:http://example.com/some-long-title
当我将其保存到我的服务器并访问带有嵌套文件夹的链接时,它只返回404,原始URL在地址栏中保持不变。我想要的是地址栏中的新位置(当然还有内容)。
答案 0 :(得分:0)
我想这或多或少是你想要的:
RewriteEngine On
ReriteRule ^/([0-9]+)/([0-9]+)/(.?)\.html$ http://example.com/$3 [L,R=301]
这可以在中央apache配置中使用。如果必须使用.htaccess文件,因为您无法访问apache配置,则语法略有不同。
答案 1 :(得分:0)
使用mod_alias,您需要RedirectMatch
,而不是常规Redirect
指令:
RedirectMatch permanent ^/([0-9]+)/([0-9]+)/(.+)\.html$ http://example.com/$3
您的上一次分组需要(.+)
,这意味着任何1个字符或更多的内容,您之前拥有的内容,(.?)
匹配任何0或者0的内容1个字符。此外,最后一个反向引用不需要括号。
使用mod_rewrite,它看起来很相似:
RewriteEngine On
RewriteRule ^/([0-9]+)/([0-9]+)/(.+)\.html$ http://example.com/$3 [L,R=301]