Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
Php 重写htaccess文件codeigniter中的url_Php_.htaccess_Codeigniter_Mod Rewrite - Fatal编程技术网

Php 重写htaccess文件codeigniter中的url

Php 重写htaccess文件codeigniter中的url,php,.htaccess,codeigniter,mod-rewrite,Php,.htaccess,Codeigniter,Mod Rewrite,我正在使用codeigniter进行开发。我使用了.htaccess文件来缩短我的URL,即从所有URL中删除index.php。 即: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] 我有一个页面,通过下面的链接显示用户的公文包 www.example.com/u

我正在使用codeigniter进行开发。我使用了.htaccess文件来缩短我的URL,即从所有URL中删除index.php。 即:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
我有一个页面,通过下面的链接显示用户的公文包

www.example.com/users/username/id

这里“users”是控制器,“username”是第一个参数,它不是唯一的,“id”是第二个参数,它是唯一的,这样我就可以显示唯一的用户组合。它调用“users”索引函数,我在其中传递此参数

现在,我希望通过.htaccess文件重写URL,使我的URL类似于“www.example.com/username/id”。 当我尝试这样做时,codeigniter将“username”作为控制器而不是参数

有没有办法做到这一点?如果是的话,我会感谢你的时间


谢谢。

从文档中可以看出,您只需添加一条路线,即可隐藏用户部分:

现在,您可以使用该链接显示用户(具有特定id),如下所示:

<a href="username/$id"> 

而不是

比如说


希望它能帮助你:)

我使用了你的推荐信,这对我帮助很大。非常感谢。
<a href="username/$id">