【问题标题】:How to Redirect Folder with 404 .htaccess - without httpd.conf?如何使用 404 .htaccess 重定向文件夹 - 没有 httpd.conf?
【发布时间】:2011-02-04 23:15:41
【问题描述】:

我无法访问 httpd.conf。如果类型一个文件夹更像 -> http://www.example.com/folder/folder2/ --> 将 404 重定向到主页,我如何重定向用户。

用户应该只能访问这个根http://www.example.com/link+custom1+custom2/

如果他们输入类似 http://www.example.com/link+custom1+custom2/onemorefolder/orTwo/ 的内容 --> 重定向

我怎样才能只使用 .htaccess 而没有 php?

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    假设您的服务器启用了 mod_rewrite,您应该能够将其放在站点根文件夹中的 .htaccess 文件中,在 DirectoryVirtualHost 部分中:

        RewriteEngine On
        RewriteRule ^(.*)/(.+) / [R=301,L]
    

    该规则将匹配任何带有斜杠和后面一些字符的 URL,并向浏览器发送 301 永久重定向(您希望 301 表示重定向,而不是 404.. 搜索引擎会选择这个并适当调整他们的链接)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-03
      • 1970-01-01
      • 2013-08-23
      • 1970-01-01
      • 1970-01-01
      • 2016-02-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多