【问题标题】:.htaccess rewrite / to index.html, all other to index.php.htaccess 重写 / 到 index.html,所有其他到 index.php
【发布时间】:2013-05-19 05:53:27
【问题描述】:

我想使用 .htaccess 来重写我网站的 url:

如果 url 是 http://mydomain.comhttp://mydomain.com/,index.html 将处理请求,所有其他 url 将转到 index.php

请帮忙!

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    这样的事情会在内部将任何没有路径或只有斜杠的请求重定向到 index.html,并将其他所有请求重定向到 index.php,并将路径作为参数。

    RewriteEngine  on
    RewriteRule ^$ index.html
    RewriteRule ^(.*)$ index.php?$1 [L]
    

    【讨论】:

      【解决方案2】:

      很简单,有两条规则。根规则(^$,匹配前导 REQUEST_URI 斜杠后的空字符串)的一条规则,其余的用于所有其他路由((.+),匹配一个或多个字符):

      RewriteRule ^$ index.html [L]
      RewriteRule (.+) index.php [L]
      

      注意:前导斜杠不会出现在源模式中。这就是第一条规则检查空字符串的原因。

      【讨论】:

        猜你喜欢
        • 2013-04-04
        • 2016-06-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多