我正在使用CMS,需要将id
和title
发送到页面content.php
,以便可以从数据库中提取数据。我试过用:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9]+)/(.*) content.php?id=$1&title=$2
但是当我导航到/ id时,它不起作用,如果我/id/title
也不起作用。我搞砸了什么?在.htaccess
中需要记住以备将来使用吗?
提前致谢!
答案 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
传入网址中的/id
为id
密钥的值,/title