使用不同的名称/变量组合访问php
我有非常棒的php 但我想把它从显示变量改为显示dir 例如:使用不同的名称/变量组合访问php,php,.htaccess,Php,.htaccess,我有非常棒的php 但我想把它从显示变量改为显示dir 例如: example.com/?mode=page&page=15至example.com/page/15 及 example.com/?mode=pic&picid=136至example.com/pic/136 但是,我只知道一种方法,例如: RewriteRule^(.*)$index.php?mode=$1&page[R] 但这只适用于一种情况,否则会导致404 我尝试使用RewriteRule^(.*)$index.php?ur
example.com/?mode=page&page=15
至example.com/page/15
及
example.com/?mode=pic&picid=136
至example.com/pic/136
但是,我只知道一种方法,例如:
RewriteRule^(.*)$index.php?mode=$1&page[R]
但这只适用于一种情况,否则会导致404
我尝试使用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]
问题是您正在将所有URL重写到
index.php?url=
因此,您的CSS文件也会“重定向”到“index.php?url=”eg
因此,您需要在.htaccess中添加“条件”,以便某些文件(或目录)不会被“重定向”。您可以在“重写规则”之前使用“重写条件”(RewriteCond)
例如,为了不“重定向”css文件“css/styles.css”,您可以这样做
RewriteCond %{REQUEST_URI} !^css/styles\.css$
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
如果我访问example.com/asd,它不会破坏css。但是,如果我键入example.com/asd/asd或多个变量,那么它会破坏cssIf,这仍然是一个值得关注的问题:您的基本URI是否直接位于域或本地主机之后?如果没有,您必须在html中的路径中引用它。
RewriteCond %{REQUEST_URI} !^css/styles\.css$
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]