【问题标题】:Apache / mod_rewrite / Periods messing with patternApache / mod_rewrite / 时期与模式混淆
【发布时间】:2010-01-16 20:47:00
【问题描述】:

第一个问题,这里什么都没有……

我正在尝试向我的 .htaccess 文件(Apache 服务器)添加一个新条目,希望能翻译此 URL:

http://platform.localhost/category.all

进入这个网址:

http://platform.localhost/index.php?page=category.all

我目前使用的 RewriteRule 是这样的:

RewriteRule ^([^/\.]+)\/?$ index.php?page=$1

到目前为止,这条规则对所有 URL 都有效,我只能假设它是打破它的时期。

我想要实现的是在“http://platform.localhost/”传递到 index.php 的“page”变量之后,URL 中有任何内容。

我知道我错过了一些愚蠢的事情,有人可以指出来吗?

干杯

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    模式说拒绝点,但你可以这样做:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]
    

    【讨论】:

      【解决方案2】:

      为什么不只是这样:

        RewriteRule index.php - [L]
        RewriteRule (.*) index.php?$1
      

      这可能会失败,因为我不记得在与模式匹配时是否包含查询字符串,所以我不确定如果你请求会产生什么结果:

      http://bla.blub/x?q=1

      另请注意,这是针对 .htaccess/directory 上下文的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-01-20
        • 2018-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多