Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess重写不';我的PHP代码不能工作_Php_.htaccess - Fatal编程技术网

.htaccess重写不';我的PHP代码不能工作

.htaccess重写不';我的PHP代码不能工作,php,.htaccess,Php,.htaccess,我想像这样重写URL127.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 U

我想像这样重写URL
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
    }
}

姓名:


您可以在
文档\u ROOT/.htaccess
文件中使用此规则:

RewriteEngine On

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

您可以在
文档\u ROOT/.htaccess
文件中使用此规则:

RewriteEngine On

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

你在运行nginx还是apache?请添加你的代码,不要添加图像,这没有帮助我在Xampp上使用apache。@Sam SwiftName:

@RedouanAzizim,在我的意思是格式问题中,将每行代码缩进4个空格,然后添加到问题中,可读性更强:)您是在运行nginx还是apache?请添加代码,不要添加图像,这没有帮助我在Xampp上使用apache。@Sam SwiftName:

@RedouanAzizim,在我的意思是使用格式的问题中,将每行代码缩进4个空格并添加到问题中,可读性更强:)