백엔드 개발 PHP 문제 index.php를 제거하는 방법

index.php를 제거하는 방법

Nov 04, 2020 am 11:15 AM
index.php

去除index.php的方法:1、在apache中,编辑httpd.conf配置文件,并在框架根目录下新建htaccess;2、在nginx中,配置“$config['index_page'] = '';”,然后重启nginx即可。

index.php를 제거하는 방법

推荐:《PHP视频教程

apache去掉index.php

  1.编辑conf/httpd.conf配置文件

  #LoadModule rewrite_module modules/mod_rewrite.so 把该行前的#去掉
로그인 후 복사

  同时对应Directory下要配置 AllowOverride All

  2.在 CI 根目录下(即在index.php,system的同级目录下)新建立一个配置文件,命名为: .htaccess 内容如下:

 RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond $1 !^(index\\.php|robots\\.txt)
  RewriteRule ^(.*)$ index.php/$1
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(application|modules|plugins|system|themes) index.php/$1 [L]
로그인 후 복사

  3.把system/application/config/config.php 中$config['index_page'] = "index.php";改为$config['index_page'] = "";

  4.重启apache

nginx去掉index.php

  1.编辑nginx.conf文件

vi /usr/local/xxxxx/nginx/conf/nginx.conf
  #nginx去掉index.php
  location / {
  rewrite ^/$ /index.php last;
  #防止某些文件夹被直接访问
  rewrite ^/(?!index\\.php|robots\\.txt|uploadedImages|resource|images|js|css|styles|static)(.*)$ /index.php/$1 last;
  }
로그인 후 복사

  2.config/config.php下配置$config['index_page'] = '';

  3..重启nginx

  去掉默认的index方法,如图的URL配置如:

  config/routes.php,配置$route['catalogues/(:any)'] = "catalogues/index/$1";

  其中(:any)表示匹配所有除CI保留关键字外的内容,后面的$1为index传入的参数内容。

  多个参数采用多个(:any),如两个参数的为:$route['catalogues/(:any)/(:any)'] = "catalogues/index/$1/$2";

  注:route规则如果同一目录下精确配置要在模糊配置上面,否则不起作用,如:

  $route['catalogues/more'] = "catalogues/more";
  $route['catalogues/(:any)'] = "catalogues/index/$1";
로그인 후 복사

  注意事项

  route规则如果同一目录下精确配置要在模糊配置上面,否则不起作用

  nginx服务器不需要.htaccess文件

위 내용은 index.php를 제거하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)