mod_rewrite:仅以数字4开头的转发参数

时间:2009-09-25 16:01:18

标签: .htaccess mod-rewrite

我正在尝试修改以下重写条件,以便只将以数字4开头的字符串作为变量重定向到process.php页面:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /process.php?variable=$1 [L]

以下

http://www.domain.com/4shopping

将映射到

http://www.domain.com/process.php?variable=4shopping

但以下不会

http://www.domain.com/shopping

原因是/ shopping只是一个普通的页面(由Wordpress提供),但/ 4shopping是一个代码,它应该映射到/process.php作为变量。

1 个答案:

答案 0 :(得分:1)

这样做:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(4[^/]*)$ /process.php?variable=$1 [L]

正则表达式意味着:

^      Start of string
(      Start capturing group (for $1)
 4     A literal "4"
 [^/]* Any character except "/", 0 or more times
)      End capturing group
$      End of string