使用.htaccess重写url

时间:2015-08-19 13:52:23

标签: php apache .htaccess mod-rewrite

我写了.htaccess来重写以下网址:

confirmreg.php

http://keralapsctuts.com/confirm-registration.html

 confirmreg.php?code=nsfoh98fkjsdf90

http://keralapsctuts.com/code/62fdd2ac2709877a81ecfd7dde9d2810/confirm-registration.html

.htaccess规则是

RewriteRule confirm-registration\.html$ confirmreg.php [QSA,L]
RewriteRule code/(.*)/confirm-registration\.html$ confirmreg.php?code=$1 [QSA,L]

Echo获取不返回代码的值

echo "Code: ". $_GET['code'];

1 个答案:

答案 0 :(得分:1)

改进代码:

RewriteRule ^confirm-registration\.html$ confirmreg.php [QSA,L]
RewriteRule ^code/([0-9a-z]+)/confirm-registration\.html$ confirmreg.php?code=$1 [QSA,L]

给RewriteRule一个开始^

RewriteRule ^

可选地,在您想要的字符中更具体。

code/([0-9a-z]+)/