如何在 CSS 和 javascript 文件未被重写的情况下从 apache .htaccess 获取重写规则?

how do I get rewrite rules working from the apache .htaccess while CSS and javascript files are not rewritten?

已经完成了其他建议的问题,但没有运气。 这些是我的 .htaccess 重写规则,主要是为了 SEO 和用户友好的目的:

Options +SymLinksIfOwnerMatch

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} !^/(images|css|js|scripts/.*)$
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # RewriteRule ^dictionary/(.*) dictionary.php [NC,L]
    RewriteRule . /index.php [L]
    RewriteRule ^dict/[^/]+/[^/]+/(.+)$   [L]
</IfModule>

如果我取消对重写规则的注释,那么对 www.xyz.com/dictionary and internally rewritten to www.xyz.com/dictionary.php 的任何请求以及添加的任何查询字符串都会导致整个站点停止工作。

我想要的是对文件夹 JS、CSS、图像和脚本的任何请求都不会被重写(所以我没有得到 /dictionary.images/xyz.jpg)和 [= dictionary.php 中包含的 30=] 个文件未被重写。

任何对现有目录的请求都不会被触及,但是如果一个不存在的目录被重写为/index.php

我怎样才能重写 'fake' 目录?我还有大约 5 个我想重写的假目录,并且 CSS、JavaScript 和图像是从他正确的路径加载的?

重写条件仅适用于下一个规则。当您在 index.php 规则及其上方的重写条件之间插入“字典”规则时,它们将停止应用该规则并破坏您的站点。您需要在 其他地方.

添加新规则

我建议添加新行以强调哪些条件符合哪些规则。

您的 dictdictionary 规则需要靠近顶部,这样这些路径就不会被您的 front controller (index.php)

尝试:

Options +SymLinksIfOwnerMatch

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^dict/[^/]+/[^/]+/(.+)$   [L]

    RewriteRule ^dictionary/(.*) dictionary.php [NC,L]

    RewriteCond %{REQUEST_URI} !^/(images|css|js|scripts/.*)$
    RewriteRule ^index\.php$ - [L]

    RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

</IfModule>