【问题标题】:Redirect /old_directory/1/2/3 to /new_directory/1/2/3 in apache2将 /old_directory/1/2/3 重定向到 apache2 中的 /new_directory/1/2/3
【发布时间】:2016-02-14 20:44:37
【问题描述】:

如何使用.htaccess 重定向如下内容:

www.example.com/old_directory/sub1/sub2/sub3

www.example.com/new_directory/sub1/sub2/sub3

【问题讨论】:

    标签: apache .htaccess web


    【解决方案1】:

    如果只需要更改顶层目录:

    外部重写(即如果您想更改浏览器 URL):

    RewriteEngine On
    RewriteBase /
    RewriteRule ^old_directory(.*) new_directory$1 [R,NC,L]
    

    内部重写(如果你想保持浏览器 URL 不变):

    RewriteEngine On
    RewriteRule  ^old_directory(.*) new_directory$1 [NC,L]
    

    这些假设您在主配置中启用了重写模块:

    LoadModule rewrite_module modules/mod_rewrite.so
    

    【讨论】:

    • jerz4lunch 上面的答案有帮助吗?
    猜你喜欢
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-10
    相关资源
    最近更新 更多