我想将此127.0.0.1/profile.php?user=userName
的网址重写为127.0.0.1/user/userName
或127.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
}
}
答案 0 :(得分:0)
您可以在DOCUMENT_ROOT/.htaccess
文件中使用此规则:
RewriteEngine On
RewriteRule ^(user)/(\w+)/?$ profile.php?$1=$2 [L,QSA,NC]