重写规则接受两个变量,并向URL添加文本


Rewrite rule takes in two variables and adds text to the URL

我已经为我的网站创建了一个htaccess文件,它将像http://www.example.com/fixture?id=1这样的URL转换为像http://www.example.com/fixtures/1这样的东西。

My htaccess file:

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^fixtures/('d+)*$ fixture.php?id=$1

这是我想要的,但不是完全SEO友好,所以我想传递两个变量homeawayhttp://www.example.com/fixture?id=1&home=Arsenal&away=Chelsea

然后重写URL,看起来像' http://www.example.com/fixtures/arsenal-vs-chelsea。

关于SO的重写规则有很多问题,但没有一个讨论在变量之间添加一小部分文本。我怎样才能使用重写规则添加URL的vs部分?

您可以使用:

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^fixtures/([^/]+)-vs-([^/]+)/?$ fixture.php?home=$1&away=$2

重写:http://www.example.com/fixture?home=Arsenal&away=Chelsea