【问题标题】:.htaccess rewrite rules do not work properly.htaccess 重写规则无法正常工作
【发布时间】:2015-06-06 12:19:17
【问题描述】:

当我像这样打开 url 时,这个 .htaccess 文件会重写为 /admin/index.php: http://example.com/admin/

http://example.com/admin/accounts/ 将请求重写为 /index.php(第一条规则)。

我的配置文件有什么问题?

AddDefaultCharset utf-8
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php [QSA,L]
RewriteRule ^admin/(.*)$ admin/index.php [QSA,L]
RewriteRule ^api/(.*)$ api.php [QSA,L]

【问题讨论】:

  • 将您的第二条和第三条规则移至 RewriteEngine on 下方。
  • 它有效。非常感谢!
  • 我会将其作为答案发布,以便被接受。

标签: apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

您的最后两条规则被忽略,因为第一条规则取代了它们,通过匹配所有(.*)

因此,最后两条规则应上移至 RewriteEngine on 下方。

【讨论】:

    猜你喜欢
    • 2011-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-05
    相关资源
    最近更新 更多