.htaccess url在index.php而不是profile.php中重写


.htaccess url rewrites in index.php and not profile.php

所以我很新的url重写和。一般的Htaccess。我想重写下面的url

/rewrite/profile/karis/2

/rewrite/profile.php?name=karis&id=2
所以。htaccess的代码是
RewriteEngine on
RewriteRule ^profile profile.php
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ profile.php?name=$1&id=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ profile.php?name=$1&id=$2

所以这工作完美,当我改变一切工作为index.php,但相同的代码不工作在profile.php

简单的php代码是
<?php
    if(isset($_GET['name']) && isset($_GET['id']))
    {
        echo "Hi ".$_GET['name'].", your id is ".$_GET['id'];   
    }
?>

知道为什么吗?

你的规则可以合并成一个,第一个也放错了地方。在您的/rewrite/.htaccess中试试:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /rewrite/
RewriteRule ^(['w-]+)/([0-9]+)/?$ profile.php?name=$1&id=$2 [L,QSA]
RewriteRule ^profile/?$ profile.php [L]