0

我有很棒的 php 但我想将它从显示变量更改为看起来像 dirs

例如:

example.com/?mode=page&page=15example.com/page/15

example.com/?mode=pic&picid=136example.com/pic/136

但是我只知道一种方法,例如:

RewriteRule ^(.*)$ index.php?mode=$1&page [R]

但这仅适用于一种情况,否则为404s

我尝试使用RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]以使整个路径通过。但是,这种方式似乎没有在我的页面中传递 CSS。

我特别迷茫...

这是我的 htaccess 文件

# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /

IndexIgnore *


RewriteEngine On


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^css/styles\.css$

RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
4

1 回答 1

0

问题是您将所有网址重写为

index.php?url=

因此,您的 CSS 文件也会“重定向”到“index.php?url=”,例如

index.php?url=css/styles.css

因此,您需要在 .htaccess 中添加“条件”,以便某些文件(或目录)不会被“重定向”。您可以通过在“RewriteRule”之前使用“RewriteCond”(条件)来做到这一点。

例如不“重定向”你可以做的css文件“css/styles.css”

RewriteCond %{REQUEST_URI} !^css/styles\.css$
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
于 2012-06-03T22:58:22.120 回答