重写查询字符串的请求

时间:2015-05-09 11:33:27

标签: regex .htaccess mod-rewrite

我在.htaccess中有这些行,它可以按照我的意愿运行。

RewriteEngine on
RewriteRule ^api$ page.php?id=api

如果你转到http://example.com/api,它会将网址重写为http://example.com/page.php?id=api,但我需要将其应用于任何字母数字输入,例如:

No request:
    http://example.com -> http://example.com/page.php?id=
Anything else:
    http://example.com/foobar123 -> http://example.com/page.php?id=foobar123

提前致谢:)

1 个答案:

答案 0 :(得分:1)

使用代码

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/page.php
RewriteRule ^(.*)$ /page.php?id=$1 [L]
相关问题