.htaccess重写在我的PHP代码中不起作用

时间:2015-11-19 16:44:47

标签: php .htaccess

我想将此127.0.0.1/profile.php?user=userName的网址重写为127.0.0.1/user/userName127.0.0.1/profile/userName。没关系,但请帮助我。

PHP代码:

<?php

require_once 'core/init.php';

if(!$username = Input::get('user')) {
    Redirect::to('index.php');
} else {
    $user = new User($username);

    if(!$user->exists()) {
        Redirect::to(404);
    } else {
        $data = $user->data();
?>

        <h3><?php echo escape($data->username); ?></h3>
        <p>Name: <?php echo escape($data->name); ?></p>

<?php
    }
}

1 个答案:

答案 0 :(得分:0)

您可以在DOCUMENT_ROOT/.htaccess文件中使用此规则:

RewriteEngine On

RewriteRule ^(user)/(\w+)/?$ profile.php?$1=$2 [L,QSA,NC]