【问题标题】:Rewrite rule for subfolder子文件夹的重写规则
【发布时间】:2012-11-20 07:31:38
【问题描述】:

我有文件结构

索引.php .htaccess 新闻/index.php 新闻/.htaccess

第一个.htaccess:

重写引擎开启 RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/news/ 重写规则。 /index.php [L]

第二个(新闻/.htaccess)

重写引擎开启 重写规则。 /index.php

请求 http://test.t/news/news/61 处理第一个 index.php 但我需要做第二个

我为第一个 .htaccess 尝试了更多选项,但没有成功

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:

    检查您的 Apache 配置文件 (httpd.conf) 并确保您用于站点的目录包含 AllowOverride 选项。

    例子:

    <Directory "/Applications/MAMP/htdocs">
        Options All
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    

    【讨论】:

    • http://test/news/news/61 是否使用了错误的 index.php? “没有成功”是什么意思?
    • 是的,第二个收到一个请求,只有http://test/news/ 没有参数( news/61 )。首先收到的任何其他请求。
    • 听起来它完全按照您的指示行事。您的组合 .htaccess 表示对于 url test/news/news/61,它应该打开 /index.php 并且不传递任何参数。如果你想让它使用 /news/index.php,那么你应该编辑你的第二个 .htaccess 说RewriteRule . index.php而不是/index.php。您需要参数中的 url 部分吗?
    • 如果您需要文章编号作为参数,请使用类似:RewriteRule news/([0-9]+) index.php?articleId=$1,它使用正则表达式匹配 news/###,并将文章编号附加到 url。见httpd.apache.org/docs/trunk/rewrite/remapping.html
    • 解析Yii中涉及的参数,需要发给他。谢谢!
    猜你喜欢
    • 2012-11-22
    • 1970-01-01
    • 2023-03-13
    • 2016-08-16
    • 2012-02-24
    • 1970-01-01
    • 2012-08-20
    • 2021-02-13
    • 2014-04-08
    相关资源
    最近更新 更多