【问题标题】:htaccess for redirect files and folder having same namehtaccess 用于重定向具有相同名称的文件和文件夹
【发布时间】:2020-01-09 00:23:04
【问题描述】:

我有同名的文件夹和文件文件。'product' 是我的文件夹,其中包含文件 integration.html、test1.html 和 test2.html。 我的文件夹结构如下所示

testproject (project folder)
   product (subfolder in testproject )

       integration.html (file in product folder)
       test1.html (file in product folder)
       test2.html (file in product folder)
   event (subfolder in testproject ) 
   product.html (file in testproject folder)

我想重定向 1) /product/integration/ 到http://test.testproject.net/product/integrations.html

Redirect 301 /product/integration/  http://test.testproject.net/product/integrations.html

2) /product to http://test.testproject.net/product

Redirect 301 /product  http://test.testproject.net/product.html

我在 htaccess 中有两个重定向规则。在访问 /product/integration/ 时

它重定向到http://test.testproject.net/product.html//integration.html 显示未找到错误

【问题讨论】:

  • 规则的顺序是什么?
  • @capeStar 抱歉,产品中没有这样的文件夹

标签: php html apache .htaccess


【解决方案1】:

使用RedirectMatch 允许使用正则表达式而不是Redirect 指令进行精确匹配:

RedirectMatch 301 ^(?i)/product/integration/?$ /product/integrations.html

RedirectMatch 301 ^(?i)/product/?$ /product.html

确保在测试前从新浏览器进行测试或完全清除浏览器缓存。

【讨论】:

  • 仍然遇到同样的问题
  • 如果您获得相同的重定向,则很可能是由于您的浏览器缓存所致。在 .htaccess 和新浏览器中仅使用这 2 条规则进行测试
  • product/ 工作正常,但 Product(P 作为大写字母不工作)
  • ok,忽略大小写不是之前的要求,但我已经更新了我的答案来解决这个问题。
  • @anubhava 我想将 Wp-content 目录中的所有内容重定向到 not-fount.html
猜你喜欢
  • 2015-10-09
  • 2018-03-08
  • 2012-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多