我想知道如何让系统从url中读取参数,而无需在php或jsp中进行GET。 例如:www.example.com/action/logout/
将与www.example.com?action=logout
相同。没有GET的URL参数
谢谢。
我想知道如何让系统从url中读取参数,而无需在php或jsp中进行GET。 例如:www.example.com/action/logout/
将与www.example.com?action=logout
相同。没有GET的URL参数
谢谢。
标准和流行的做法是使用.htaccess文件。你应该学习如何使用.htaccess重写规则。它应该看起来像:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)(/.*)?$ $3?$1=$2 [N,QSA]
RewriteRule ^(/[^/]+|[^/]+/|/?)$ /index.php [L,QSA]
这将运行在Apache级别,这可能是你想要的。
在的情况下是要格式化它建议使用重写规则.htaccess文件中
RewriteEngine ON
RewriteRule ^(.*)action/([a-zA-Z0-9]+).*$ $1?action=$2
这将导致服务器解释干净URLS
www.example.com/action/logout/
为
www.example.com?action=logout
以及
www.example.com/subdirectory/action/logout/otherstuff
为
www.example.com/subdirectory/?action=logout
请注意,新增/otherstuff
被省略,但查询传递到子目录。你将需要定制你使用正则表达式的最终规则
[parse_url](http://php.net/manual/function.parse-url.php) –
从重写规则开始。 – Brad
您是否试图在没有GET的情况下执行此操作,或者您是否暗示您无法使用URL来格式化GET原因? – varubi