【问题标题】:How to redirect example.com/x/restofurl to example.com/y/restofurl with htaccess如何使用 htaccess 将 example.com/x/restofurl 重定向到 example.com/y/restofurl
【发布时间】:2012-10-24 16:20:18
【问题描述】:

我有一个类似example.com/x的网址

如何使用 htaccess 将其重定向到 example.com/y

顺便说一句,我不想​​丢失 URL 的其余部分。

当前 .htaccess 文件的样子;

<ifModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-s
    RewriteRule ^(.*)\.[\d]+\.(css|js)$ $1.$2 [L]

        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]

</ifModule>

【问题讨论】:

    标签: .htaccess http-redirect


    【解决方案1】:

    查看documentation

    RewriteEngine on
    RewriteRule ^/x/(.+) /y/$1 [R,L]
    

    【讨论】:

    • 没用,我添加了当前的 htaccess 文件,因为已经有重写规则可能是这个原因
    • 尝试将 RewriteRule 移动到 HTACCESS 文件的顶部,紧随“RewriteEngine on”之后。
    【解决方案2】:

    好的,我终于找到了解决方案;在这种情况下,基本重定向 301 就足够了;

    redirect 301 /x /y
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-13
      • 2014-10-17
      • 2016-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多