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 具有多个参数的apache重写规则_Php_.htaccess - Fatal编程技术网

Php 具有多个参数的apache重写规则

Php 具有多个参数的apache重写规则,php,.htaccess,Php,.htaccess,我对.htaccess是个新手,我正试着做这样的东西 localhost/easyApy/?tablename=%tablename% => localhost/easyApi/%tablename% localhost/easyApy/?tablename=%tablename%&action=get&id=%id% => localhost/easyApi/%tablename%/get/%id% localhost/easyApy/?tablename=%tab

我对.htaccess是个新手,我正试着做这样的东西

localhost/easyApy/?tablename=%tablename% => localhost/easyApi/%tablename%
localhost/easyApy/?tablename=%tablename%&action=get&id=%id% => localhost/easyApi/%tablename%/get/%id%
localhost/easyApy/?tablename=%tablename%&action=delete&id=%id% => localhost/easyApi/%tablename%/delete/%id%
localhost/easyApy/?tablename=%tablename%&action=update&id=%id% => localhost/easyApi/%tablename%/update/%id%
localhost/easyApy/?tablename=%tablename%&action=add => localhost/easyApi/%tablename%/add

谢谢!:)

您很可能正在寻找这样的东西:

RewriteEngine on
RewriteRule ^/?easyApi/(\w+)/get/(\d+)/?$    /easyApi/index.php/?tablename=$1&action=get&id=$2 [L]
RewriteRule ^/?easyApi/(\w+)/delete/(\d+)/?$ /easyApi/index.php/?tablename=$1&action=delete&id=$2 [L]
RewriteRule ^/?easyApi/(\w+)/update/(\d+)/?$ /easyApi/index.php/?tablename=$1&action=update&id=$2 [L]
RewriteRule ^/?easyApi/(\w+)/add/?$          /easyApi/index.php/?tablename=$1&action=add [L]
RewriteRule ^/?easyApi/(\w+)/?$              /easyApi/index.php/?tablename=$1 [L]
注意:这假设您的
id
是数字类型

该规则集同样适用于动态配置文件或http服务器主机配置

请记住,以这种透明的方式公开数据库是一个主要的安全问题。不,事实上,这只是为了“本地”使用,并不是一个很好的回答。一点也不



还有一个一般性提示:您应该始终希望将这些规则放在http服务器主机配置中,而不是使用动态配置文件(“.htaccess”)。这些文件是出了名的容易出错,难以调试,而且它们确实降低了服务器的速度。只有在您无法控制主机配置的情况下(读:非常便宜的主机服务提供商),或者如果您的应用程序依赖于编写自己的重写规则(这显然是一个安全噩梦),才提供它们作为最后一个选项。

因此,您正在尝试创建一个表。或字符串列表。或者别的什么。是的。你有什么问题吗?
easyApy
应该是路径
localhost/easyApi
my bad:)我怀疑
localhost/easyApi
实际上是一条路径。读起来更像是一个缺少协议方案并指向本地系统的URL。主配置文件中的语法错误可能会导致整个服务器停止。(其他路径上的请求不会读取.htaccess。)因此,请仅在生产服务器配置中放置防水且经过彻底测试的重写。完整路径是:
localhost/easyApi/index.php?tablename=%tablename%
@itzikb再次,
localhost/easyApi/index.php?tablename=%tablename%
不是路径。它是一个可以解释为URL
http://localhost/easyApi/index.php?tablename=mytable
。其中的路径是
/easyApi/index.php
。但这只是一个猜测。请准确命名,以避免误解。