Apache .htaccess重写规则,带有2个GET参数

时间:2013-01-01 08:59:00

标签: .htaccess apache2

我正在使用CMS,需要将idtitle发送到页面content.php,以便可以从数据库中提取数据。我试过用:

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

RewriteRule ^([0-9]+)/(.*) content.php?id=$1&title=$2

但是当我导航到/ id时,它不起作用,如果我/id/title也不起作用。我搞砸了什么?在.htaccess中需要记住以备将来使用吗?

提前致谢!

1 个答案:

答案 0 :(得分:2)

你可以试试这个:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /([^/]+)/([^/]+)
RewriteRule .* http://example.com/content.php?key1=%1&key2=%2  [L]

它会默默地映射:

http://example.com/id/title

对此:

http://example.com/content.php?key1=id&key2=title

传入网址中的/idid密钥的值,/title

的值为{{1}}
相关问题