我基本上是想把所有不是文件的东西(.css、.js、.jpg等)重写到index.php来创建符号链接。我在.htaccess文件中的代码适用于我的根目录和一个子目录。因此,"localhost/"answers"localhost/help"都有效,但"localhost/help.article-27"不起作用。当我尝试使用第二个子目录(包括JS和CSS文件)时,.htaccess似乎重写了所有。有人知道为什么吗?这是我的代码:
<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>
正如darren在评论中提到的那样,它不需要有$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>