带有1或2个参数的mod_rewrite网址

时间:2013-08-28 08:00:22

标签: .htaccess mod-rewrite apache2

网址:http://example.com/good_game/osmp/

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /?service=$1&terminal=$2 [L,QSA]

我收到了

Array ( [service] => good_game [terminal] => osmp )

没关系,但是

网址:http://example.com/good_gamehttp://example.com/good_game/

我需要

Array ( [service] => good_game)

并返回404未找到

1 个答案:

答案 0 :(得分:1)

这应该适用于:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*|)/?([^/]*|)/?$ /?service=$1&terminal=$2 [L,QSA]

将匹配:

http://example.com/good_game/osmp/
http://example.com/good_game/osmp
http://example.com/good_game/
http://example.com/good_game