.htaccess路由PHP

Bob*_*ban 7 php apache .htaccess

我试图在PHP的htaccess中编写一些简单的路由

我的文件现在看起来像这样:

RewriteEngine On
RewriteBase /webservices/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ server.php [QSA,L]
Run Code Online (Sandbox Code Playgroud)

但它没有任何作用.

我想用htaccess的东西是所有对server.php的调用都是这样的:

http://localhost:8888/webservices/server.php?username=test&password=test
Run Code Online (Sandbox Code Playgroud)

要写

http://localhost:8888/webservices/server/u/test/p/test/
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我吗?

Ráp*_*rás 5

它实际上是有效的,因为它将所有查询重定向到server.php.因此

http://localhost:8888/webservices/server/u/test/p/test/
Run Code Online (Sandbox Code Playgroud)

可以server.php通过explode()$_SERVER["REQUEST_URI"]数组上轻松捕获部分URI来处理.忘了

http://localhost:8888/webservices/server.php?username=test&password=test
Run Code Online (Sandbox Code Playgroud)

URL结构,您将不再需要它,因为使用.htaccess您刚刚编写的,您可以动态处理您的服务器上的每个请求server.php.

[QSA]在你.htaccess的URI中追加查询字符串,这是不需要的,因为我们想要摆脱它,对吧?由于您不会使用该格式,因此可以删除QSA标记.