htaccess,重写特定子目录,但不重写其下的其他子目录



我有一个子目录/categories/stories/我想重写/books/但我不想重写类似/categories/stories/horror的东西。我正在执行以下操作,但它没有效果:

RewriteCond ${REQUEST_URI} ^/categories/stories[/]?
RewriteCond ${REQUEST_URI} !^/categories/stories/+[/]?
RewriteRule ^(.*) /books/ [R=301,L]

结果是,例如,如果一个人去了,http://bookstore.com/categories/stories他们去了http://bookstore.com/bookshttp://bookstore.com/categories/stories/horror没有重写。

您可以在正则表达式模式中使用锚点:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/categories/stories/?$ [NC]
RewriteRule ^ /books/ [R=301,L]

模式^/categories/stories/?$将匹配/categories/stories//categories/stories,但不匹配/categories/stories/anything

此外,请确保清除浏览器缓存或使用其他浏览器来测试此更改。

最新更新