简体   繁体   English

URL 重写 CodeIgniter - 使用 GET ID

[英]URL Rewriting CodeIgniter - With GET ID

I read all the topic about the next question but i cant fin solution.. On my CodeIgniter project, i have this link to see user profil:我阅读了关于下一个问题的所有主题,但我无法找到解决方案。 在我的 CodeIgniter 项目中,我有这个链接可以查看用户资料:

user/profil?id=1

But i want但我想要

user/profil/1

And i cant find solution.. Where put the code ?我找不到解决方案.. 代码放在哪里? Do i need ROUTE or .htaccess ?我需要 ROUTE 还是 .htaccess ? My htacess look like this.我的 htacess 看起来像这样。

#   Empêche la visualisation de l'arborescence, n'a rien à voir avec le masquage du « index.php ».
Options -Indexes

#   Active le module de réécriture d'URL.
RewriteEngine on

#
#   Fixe les règles de réécriture d'URL. Ici, nous utilisons une liste blanche.
#

#   Toutes les URL qui ne correspondent pas à ces masques sont réécrites.
RewriteCond $1 !^(index\.php|assets/|robots\.txt|uploads)

#   Toutes les autres URL vont être redirigées vers le fichier index.php.
RewriteRule ^(.*)$ index.php/$1 [L]

My profil controllers:我的配置文件控制器:

public function profil()
{
    // Récupération de l'ID dans l'url
    $this->data['id'] = $this->input->get('id', TRUE);

// Statistiques du profil
$this->data['countReview'] = $this->review_model->countReview($this->data['id']);

// Chargement du profil de l'utilisateur
if (ctype_digit($this->data['id'])) {
    if ($this->user_model->getUser($this->data['id'])) {
        $this->data['users'] = $this->user_model->getUser($this->data['id']);
        $this->data['reviewsNext'] = $this->review_model->getReviewsByUser_Next($this->data['id']);
        $this->data['reviewsPrevious'] = $this->review_model->getReviewsByUser_Previous($this->data['id']);
    } else {
        $this->session->set_flashdata('error', 'Utilisateur introuvable.');
    }
} else {
    $this->data['error_report'][] = "Utilisateur introuvable.";
}

$this->load->view('template/header');
$this->load->view('template/menu');
$this->load->view('user/profil', $this->data);
$this->load->view('template/footer');

} }

Thanks for your answer.感谢您的回答。

# Redirect profile.php?id=1 to profile/1
RewriteCond %{THE_REQUEST} \s/profile\.php\?id=([0-9]+)\s [NC]
RewriteRule ^/profile/%1? [R=301,L]
RewriteRule ^profile/([0-9]+)$ /profile.php?id=$1 [L]

Should work.应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM