htaccess重写规则无法正常工作

时间:2013-07-19 12:41:33

标签: php regex .htaccess mod-rewrite url-rewriting

我有以下htaccess文件

Options +FollowSymLinks

RewriteEngine On

#profile view
RewriteRule ^([a-zA-Z0-9.]+)/?$ profile.php?id=$1

当我转到我的网址并输入http://www.mysite.com/username

然后在 profile.php 文件中

<?php
    print_r($_GET);
    die();
?>

并打印出来

Array ( [id] => profile.php )

它应该打印出来

Array ( [id] => "username" )

所以我想我的重写规则有问题吗?

3 个答案:

答案 0 :(得分:1)

#profile view
RewriteRule ^([a-zA-Z0-9.]+)?$ profile.php?id=$1

试试

编辑:

RewriteRule ^(。*)?$ profile.php?id = $ 1 [QSA]

OR

RewriteRule ^([a-zA-Z0-9。] +)?$ profile.php?id = $ 1 [QSA]

答案 1 :(得分:1)

最后添加QSA:

RewriteRule ^([a-zA-Z0-9.]+)/?$ profile.php?id=$1 [QSA]

答案 2 :(得分:0)

试试这个htaccess代码:

RewriteEngine On
RewriteRule ^([^/]+)$ /profile.php?id=$1