【问题标题】:How to make inner redirect for pages with url's which contains filenames not at end, but between slashes如何为包含不在末尾但在斜杠之间的文件名的 url 页面进行内部重定向
【发布时间】:2019-08-08 11:42:34
【问题描述】:

我想在 Apache 2.4.29 的 htacess 中为这样的网址进行内部重定向:

  • example.com/file.php/dir/dirnext
  • example.com/dir/file.html/
  • example.com/dir/dirnext/file.jpg/onemoredir/

我的意思是如果任何文件名出现在两个斜杠之间的 url -> 重定向到 404 页面。我试试这个,但它不起作用:

RewriteRule ^/(.*)/$ index.php?route=error/not_found [L]

【问题讨论】:

  • nginx 并不真正支持mod_rewrite.htaccess
  • anubhava,对不起-我的错误。服务器是 apache 2.4.29
  • 好的,即使 xyz.123 不作为文件存在,您是否也希望对任何看起来像文件名的内容进行内部重写,例如 example.com/foo/xyz.123/bar
  • @anubhava,是的。

标签: .htaccess url redirect mod-rewrite


【解决方案1】:

你可以使用这样的规则:

RewriteRule (?:^|/)[\w-]+(?:\.[\w-]+)+/ index.php?route=error/not_found [L,QSA]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-12
    • 2019-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    相关资源
    最近更新 更多