简体   繁体   中英

CodeIgniter remove index.php from href

In a CodeIgniter App

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?

This is done without success:

1) added to application/routes.php

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

2) added to 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

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.

<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

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['index_page'] = '';

The rewrite_module should be activated in apache

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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