【问题标题】:301 Redirect Remove first directory301 Redirect 删除第一个目录
【发布时间】:2015-07-19 19:53:44
【问题描述】:

我有几个网址我想从网址中删除整个目录部分。 htaccess 301 重定向是什么?有人可以帮忙吗?

例如。

https://example.com/first-lastname-word1-word2/biography/firstnamelastname
https://example.com/first-lastname-word1-word2/activity/firstnamelastname
https://example.com/first-lastname-word1-word2/announcements/firstnamelastname
https://example.com/first-lastname-word1-word2/wall/firstnamelastname

成为https://example.com/activity/firstnamelastname https://example.com/biography/firstnamelastname等等等等

【问题讨论】:

    标签: apache .htaccess mod-rewrite rewrite http-status-code-301


    【解决方案1】:

    使用mod_rewrite 保持这条规则第一条规则就在RewriteEngine 行的下方:

    RewriteEngine On
    
    RewriteCond %{REQUEST_URI} !^/(memorial-photos|videos|images|category)/ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^[^/]+/([^/]+/[^.]+)$ /$1 [L,NE,R=301]
    

    【讨论】:

    • 这似乎不起作用。我只重定向到子域,没有加载 css 文件。
    • 好的。这似乎可以解决问题,但是它与我拥有的其他网址(例如example/videos/video/myvideo.html)冲突。它使它成为example.com/video/myvideo.html。如何选择退出我可以定义的某些目录。
    • 它不起作用的原因与我上面提到的相同。我想要它,所以对某些目录(例如视频)没有效果,
    • 检查更新的代码以跳过此重写中的一些目录
    • 好的,代码确实有效,但是我有一些较长的 url,不幸的是,这些 url 不适用于规则。例如。 example.com/memorial-photos/category/3064/tylernickelson 会显示为 example.com/3064/tylernickelson,即使我告诉它跳过 /memorial-photos/
    猜你喜欢
    • 2011-12-16
    • 1970-01-01
    • 2017-06-29
    • 2021-01-30
    • 2018-12-10
    • 2017-08-24
    • 1970-01-01
    • 2011-07-15
    • 1970-01-01
    相关资源
    最近更新 更多