Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用不同的名称/变量组合访问php_Php_.htaccess - Fatal编程技术网

使用不同的名称/变量组合访问php

使用不同的名称/变量组合访问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

我有非常棒的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?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]