I want to rewrite the URL like this 127.0.0.1/profile.php?user=userName
to 127.0.0.1/user/userName
or 127.0.0.1/profile/userName
. it doesnt matter, but please please help me.
PHP Code:
<?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
}
}
You can use this rule in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteRule ^(user)/(\w+)/?$ profile.php?$1=$2 [L,QSA,NC]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.