如何通过htaccess在codeigniter中隐藏index.php和控制器名称 [英] how to hide index.php and controller name in codeigniter by htaccess

查看:32
本文介绍了如何通过htaccess在codeigniter中隐藏index.php和控制器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的codeignier网址网站隐藏index.php和控制器名称我也想替换这个词吗?seo = test-product ad/test-product

i want to hide index.php and controller name from my codeignier url website also i want to replace this term ?seo=test-product ad /test-product

我在下面提到了我的htaccess文件,请引导我如何解决此问题,我尝试了很多没有帮助的事情

i have mention my htaccess file below please guild me how to fix this issue i have tried many things none helps

 RewriteEngine On
 RewriteCond %{HTTPS} off [OR]
 RewriteCond %{HTTP_HOST} ^www\. [NC]
 RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
 RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>

推荐答案

首先,我们在项目目录中添加(.htaccess)(这只是扩展文件)文件扩展名

这是我的项目文件目录位置 http://localhost/demoproject demoproject是我的项目名称

复制以下代码并创建(.htaccess)文件并将其粘贴到(.htaccess)文件下
这些文件在项目目录下创建

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


# Disable Directory Browsing
Options All -Indexes

再将一个(.htaccess)文件创建到视图文件夹中

复制以下代码并将其粘贴到新创建的(.htaccess)文件下

<IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>

通常对控制器文件进行编码 DemoController.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class DemoController extends CI_Controller 
{
	public function index()
	{
        $data['demo'] = 'hello world';
        $this->load->view('DemoView', $data);
	}
}	

enter code here

通常对视图文件进行编码 DemoView.php

<!DOCTYPE html>
<html>
<head>
	<title>demo</title>
</head>
<body>
      <h1>
      	<!-- $demo is the $data of object that defind our DemoController. -->
           <?php echo $demo ?>
      </h1>
</body>
</html>

运行localhost,仅键入localhost/project_name/controller_name

此处我们使用 demoproject 作为项目名称,并 DemoController 作为控制器名称 http://localhost/demoproject/DemoController

here we use demoproject as project name and DemoController as controller name http://localhost/demoproject/DemoController

如果您的代码未执行,请发表评论

这篇关于如何通过htaccess在codeigniter中隐藏index.php和控制器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆