【问题标题】:Rewrite *all* non-file requests to index.php with htaccess使用 htaccess 重写 *all* 对 index.php 的非文件请求
【发布时间】:2016-01-04 00:15:54
【问题描述】:

我基本上试图将所有不是文件(.css、.js、.jpg 等)的内容重写为 index.php 以创建符号链接。我在 .htaccess 文件中的代码适用于我的根目录和单个子目录 So。 “localhost/”和“localhost/help”都可以工作,但“localhost/help/article-27”不起作用。当我尝试使用第二个子目录(包括 JS 和 CSS 文件)时,.htaccess 似乎重写了 everything。有谁知道这是为什么?这是我的代码:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [L]
</IfModule>

【问题讨论】:

  • 你应该不需要那里的RewriteCond $1 !\.(gif|jpe?g|png)$ [NC] 行。
  • help/ 也有 .htaccess 吗?

标签: php apache .htaccess mod-rewrite


【解决方案1】:

正如 darren 在 cmets 中提到的,它不需要 $1 !!.(gif|jpe?g|png)$ [NC]

这适用于所有级别和 CSS 文件,无论是符号链接/直接链接。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [L]
</IfModule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-25
    相关资源
    最近更新 更多