代码之家  ›  专栏  ›  技术社区  ›  BrynJ

将特定文件请求(在任何位置)重定向到特定位置

  •  0
  • BrynJ  · 技术社区  · 16 年前

    我有一个特定的文件,我们称之为“myfile.abc”,我需要重定向到一个特定的位置,不管它是从哪个位置请求的。例如:

    /folder1/myfile.abc
    /folder2/myfile.abc
    /folder3/myfile.abc
    

    我需要将以上所有内容重定向到(例如):

    /myfolder/myfile.abc
    

    如何在.htaccess文件中实现这一点?

    为了响应Gumbo的回答,我现在在.htaccess文件中有以下内容:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !=myfolder
    RewriteRule ^([^/]+)/myfile.abc$ myfolder/myfile.abc [L]
    RewriteRule . /index.php [L]
    </IfModule>
    
    1 回复  |  直到 16 年前
        1
  •  2
  •   Gumbo    16 年前

    试试这个:

    RewriteEngine on
    RewriteCond $1 !=myfolder
    RewriteRule ^([^/]+)/myfile\.abc$ myfolder/myfile.abc [L]
    

    如果需要外部重定向,请添加 R 带有可选重定向状态代码的标志( [L,R] / [L,R=301] )。