将文章从重定向到410的目录重定向到301

时间:2017-02-24 12:38:14

标签: php apache .htaccess redirect mod-rewrite

我已将目录重定向到.htaccess

中的410
Redirect 410 /books/videos/

现在我想编写一条规则,将某些文章从/ books / videos /重定向到301页面。我尝试了如下

RewriteRule ^(.*)/books/videos/how-to-find-videos.html /books/how-to-find-videos.html [L,R=301]

当我访问www.mysite.com/books/videos/how-to-find-videos.html时,它显示了410页。这意味着301规则未在此处应用。如何为同一目录创建410 and 301

提前致谢。

1 个答案:

答案 0 :(得分:1)

不要混合来自不同Apache模块的RedirectRewriteRule指令。

按照给定的顺序这样做:

RewriteEngine On

# specific files are redirected with 301
RewriteRule ^/?books/videos/how-to-find-videos\.html$ /books/how-to-find-videos.html [L,R=301,NC]

# remaining URIs from this path to get 410
RewriteRule ^/?books/videos/ - [L,R=410]

确保在测试之前清除浏览器缓存。