简体   繁体   English

CodeIgniter从href移除index.php

[英]CodeIgniter remove index.php from href

In a CodeIgniter App 在CodeIgniter应用程序中

this link works 该链接有效

<a href="index.php/controller">link</a>

while this one doesn't 虽然这个不

<a href="controller">link</a>

What's wrong with configuration? 配置有什么问题? What has to be changed in order links work without "index.php/" at the beginning? 为了使链接在开始时没有“ index.php /”的情况下必须进行哪些更改?

This is done without success: 这样做没有成功:

1) added to application/routes.php 1)添加到application / routes.php

$route['(:any)'] = 'controller';

2) added to application/.htaccess 2)添加到application / .htaccess

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

<Files "index.php">
AcceptPathInfo On
</Files>

3) uncommented in etc/apache2/httpd.conf 3)在etc / apache2 / httpd.conf中未注释

LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so

First of all you should blank the 首先,您应该将

$config['index_page'] = '';

in config config.php Then write the following code in .htaccess placed in your project's main directory. 在config config.php中,然后在放置在项目主目录中的.htaccess中编写以下代码。

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

Use this in your .htaccess to remove the index.php from the url 在您的.htaccess中使用它从网址中删除index.php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]

Your link should be 您的链接应该是

<a href="/controller">link</a>

Config.php should be Config.php应该是

$config['index_page'] = '';

The rewrite_module should be activated in apache rewrite_module应该在apache中激活

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

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