【问题标题】:htaccess remove folder redirecthtaccess 删除文件夹重定向
【发布时间】:2018-02-24 13:01:20
【问题描述】:

我在从 url 中删除文件夹时遇到问题。我希望谷歌/旧链接不会损坏。旧网页有几个部分具有这样的结构

example.com/news/items/entry1.html
example.com/news/items/entry2.html
example.com/blog/items/foo.html

新页面的网址如下:

example.com/news/entry1
example.com/news/entry2
example.com/blog/foo

删除 html 相当简单

<IfModule mod_rewrite.c>
RewriteEngine On

# Send would-be 404 requests to Craft

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php [QSA,L]

RewriteCond %{THE_REQUEST} /([^.]+)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
</IfModule>

我正在努力的部分是删除“项目”部分。我发现的规则仅适用于“example.com/items/subfolder1/...”之类的请求路径

任何帮助将不胜感激。

【问题讨论】:

    标签: apache .htaccess url redirect


    【解决方案1】:

    要从 URL 中删除 /items/,您可以在 .htaccess 文件中使用以下内容:

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

    例如,这将获取 URL:http://example.com/news/items/entry1 并将其转换为 http://example.com/news/entry1

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

    【讨论】:

      猜你喜欢
      • 2019-03-05
      • 2013-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多