Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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
将URL字符串传递给php而不使用$\u GET变量_Php_.htaccess_Url - Fatal编程技术网

将URL字符串传递给php而不使用$\u GET变量

将URL字符串传递给php而不使用$\u GET变量,php,.htaccess,url,Php,.htaccess,Url,在我的本地服务器(XAMPP)上,文件的内容。htaccess是: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/.]+?)(/.+)?$ index.php/$1 [L] 在服务器上上载此文件后,我无法再传递参数。我收到一条消息“找不到文件。” 例如,在本地服务器上,我传递到url:www.foo.com/admin。PHP变

在我的本地服务器(XAMPP)上,文件的内容。htaccess是:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^/.]+?)(/.+)?$ index.php/$1 [L]
在服务器上上载此文件后,我无法再传递参数。我收到一条消息“找不到文件。”

例如,在本地服务器上,我传递到url:www.foo.com/admin。PHP变量$u SERVER[“PATH\u INFO”]等于“admin”

不幸的是,在服务器上这不起作用。有人能解释为什么吗

我不想使用此规则
#RewriteRule^([^/]+?)(/.+)?$index.php?$1[L]
。因为这样我就无法传递$\u GET参数。www.foo.com/admin?id=1

您可以使用此规则

RewriteRule ^(.*)$ index.php?/$1 [L]
它只是说匹配
index.php/

[L]
告诉服务器一旦应用了该规则就停止重写

我希望这能解决你的问题

(我不会对
^([^/]+?)(/.+)?$
部分发表评论,但我想它可能过于复杂了。)

因此,您可以尝试:

                                       ↓↓       ↓↓↓
RewriteRule ^([^/.]+?)(/.+)?$ index.php?/$1 [L, QSA]
  • 根据我自己的经验,在某些服务器上可以省略
    ,但添加它更兼容
  • 然后,您需要一个查询字符串,这样客户端的查询字符串就不会被删除
  • 您不应该省略斜杠,而应该使用
    ?/$1
    ,这样应用程序就可以更好地确定重写的查询字符串中关于URL修饰的部分。例如,如果转到
    example.org/controller?foobar
    ,重写的查询字符串将是
    ?/controller&foobar

对于问题末尾的规则,您必须添加。@GrasDouble谢谢!你救了我!