Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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 使用codeigniter隐藏Url_Php_.htaccess_Codeigniter - Fatal编程技术网

Php 使用codeigniter隐藏Url

Php 使用codeigniter隐藏Url,php,.htaccess,codeigniter,Php,.htaccess,Codeigniter,我正在使用codeigniter。。。我想要一个干净的网址从下面的网址 http://localhost:8080/rtvnews/index.php/home/videonews?id=67598/newstitle 这里home=>controller,videonews=>function和?id=6586565是一个url字符串 我想删除/index.php/home/videonews?id=67598并替换为/news/ 下面是我需要获得的最终url http://loc

我正在使用codeigniter。。。我想要一个干净的网址从下面的网址

  http://localhost:8080/rtvnews/index.php/home/videonews?id=67598/newstitle 
这里home=>controller,videonews=>function和?id=6586565是一个url字符串

我想删除/index.php/home/videonews?id=67598并替换为/news/

下面是我需要获得的最终url

  http://localhost:8080/rtvnews/news/newstitle 
按照以下步骤操作

步骤1:.htaccess(根文件夹中的一个)

步骤2:routes.php 在下面添加代码

$route['rtvnews/news/newstitle'] = 'Your controller/method']; //Just a syntax to change the route in codeigniter. You can change the url as per you want.

要从url隐藏index.php,请在htaccess之后使用

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

认为新闻标题是唯一的:

转到route.php文件(application/config/routes.php)。新增 路线规则如下

在您的视图文件中

您的请求转到主页/vidonews功能,您可以在其中获取 newstitle作为参数

在您的controller.php函数中

认为id是唯一的:

添加新的路由规则,如下所示

在view.php文件中

现在,您的请求转到home/vidonews功能,在那里您可以获得 newsId作为参数。在您的controller.php函数中


无论你做了什么,你都必须传递ID。但是传递方法是可以改变的。你应该尝试阅读清楚解释路由和URL格式的文档。我也不明白,当CodeIgniter默认值与之相反时,你怎么会有一个带有查询字符串的URL。亲爱的,谢谢你的回复。我想在单击新闻标题时传递新闻id。但url是。但我想。你的问题还存在吗?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
$route['rtvnews/news/(:any)'] = 'home/videonews/$1';
<a href="<?php echo base_url()."rtvnews/new/".$newstitle; ?>" > News Title</a>
http://localhost:8080/rtvnews/news/uniquenewstitle  
function vidonews($newsTitle){}
$route['rtvnews/news/(:num)'] = 'home/videonews/$1';
<a href="<?php echo base_url()."rtvnews/new/".$newsId; ?>" > News Title</a>
http://localhost:8080/rtvnews/news/newsId
function vidonews($newsId){}