【问题标题】:HtaccessRules to redirect my websiteHtaccess 规则重定向我的网站
【发布时间】:2011-07-17 07:30:41
【问题描述】:

嗨,你们中的任何人都可以建议我如何使用 htaccess 重写规则将我的页面 http://testsite.com/about.php 重定向到 http://testsite.com/about/。在页面 url 中不使用任何查询字符串我需要重写它

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    我认为您不需要重定向而是重写。重定向意味着通知客户端重新查询重定向的 url,而重写意味着告诉服务器将 url 解释为其他 url。 并且您不想将 about.php 重写为 /about/ 但反过来。您希望您的用户输入 /about/ 并且该 url 由 /about.php 处理

    这是由以下人员完成的:

    RewriteEngine on # this line enables rewrite
    RewriteRule /about/$ /about.php
    RewriteRule /about$ /about.php
    

    我不确定是否真的需要以上两种方法还是只需要一种(我现在无法访问 apache 进行测试)

    如果您确实希望按照您所写的那样进行重定向,请使用这个免费的重定向生成器:http://www.htaccessredirect.net/(这比学习匹配条件的所有怪癖更容易) 在你的情况下,这将是:

    Redirect 301 /about.php /about/
    

    【讨论】:

    • 好的,谢谢。我已经使用以下代码行在 RewriteRule ^about/$ about.php 上实现了 RewriteEngine。
    猜你喜欢
    • 1970-01-01
    • 2019-09-01
    • 2017-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-22
    相关资源
    最近更新 更多