【问题标题】:.htaccess reverse rewrite without looping?.htaccess 反向重写而不循环?
【发布时间】:2010-01-15 11:13:28
【问题描述】:

我有一个名为 bfly.php 的现有页面,我需要将其更改为 butterfly-jewelry.php

我想这样做,如果有人访问 URL butterfly-jewelry.php 他们会得到 bfly.php 页面,但 url 不会改变它保持为 butterfly-珠宝.php。但是,如果有人直接访问 bfly.php,则 url 将更改为 butterfly-jewelry.php

有没有办法在不陷入重写循环的情况下做到这一点?

谢谢!

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    您可以将文件重命名为例如bfly1.php 然后使用这个:

    RewriteRule ^butterfly-jewelry\.php bfly1.php [L,QSA]
    RewriteRule ^bfly\.php http://yourhost.com/butterfly-jewelry.php [L,QSA,R=301]
    

    (我尝试了 Blixt 的解决方案,但它导致了一个无限循环,尽管有 L 标志。)

    【讨论】:

    • 实际上,我想如果我要更改文件名,我只需将 bfly.php 更改为 butterfly-jewelry.php,然后使用答案中的第二行。谢谢!
    【解决方案2】:

    您可以使用 Last Rule 和 Redirect 标志来做您想做的事(请参阅the mod_rewrite documentation):

    # Rewrite request to bfly.php, and then stop the rewrite engine.
    RewriteRule ^butterfly-jewelry\.php$ bfly.php [L]
    # Redirect the client to butterfly-jewelry.php with "Permanently Moved" status
    RewriteRule ^bfly\.php$ butterfly-jewelry.php [L,R=301]
    

    我还没有测试过以上,但我相信它应该可以工作。

    【讨论】:

    • 谢谢,我认为这是在正确的轨道上,但两个网址现在都将我带到 www。我的域。 com/var/www/vhosts/MYDOMAIN.com/httpdocs/butterfly-jewelry.php
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-09
    • 2011-02-16
    • 2019-09-16
    • 2014-02-28
    • 2019-08-05
    相关资源
    最近更新 更多