简体   繁体   English

从 url codeigniter 中删除 index.php

[英]Remove index.php from url codeigniter

i have the same problem as many people to remove the index.php from url in codeigniter.我和很多人有同样的问题,要从 codeigniter 的 url 中删除 index.php。

i always done all response from precedent answer, but i always can access to a url with index.php我总是从先前的答案中完成所有响应,但我总是可以使用 index.php 访问 url

this url work : https://www.domaine.tld/Test but i can access : https://www.domaine.tld/index.php/Test (work too)这个 url 工作: https://www.domaine.tld/Test但我可以访问: https://www.domaine.tld/index.php/Test (也工作)

i dont have any link in my site which include index.php but my question is about how redirect url with index.php to dont have duplicate content.我的网站中没有包含 index.php 的任何链接,但我的问题是如何使用 index.php 重定向 url 以防止重复内容。

thanks for your answer.感谢您的回答。

Codeigniter have beautiful documentation.you can find all things related Codeigniter is in Codeigniter user_guide for now to solve your issue create .htaccess file in root and paste following code Codeigniter 有漂亮的文档。你现在可以在 Codeigniter user_guide 中找到所有与 Codeigniter 相关的东西来解决你的问题在 root 中创建.htaccess文件并粘贴以下代码

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

And then also remove the index.php from然后也删除index.php

application/config/config.php

$config['index_page'] = 'index.php';

changes to更改为

$config['index_page'] = '';

Learn more at: https://www.codeigniter.com/userguide3/general/urls.html了解更多信息: https : //www.codeigniter.com/userguide3/general/urls.html

Put this in your .htaccess :把它放在你的.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

Open config.php and do following replaces打开 config.php 并执行以下替换

$config['index_page'] = "index.php"

to

$config['index_page'] = ""

Go to your config.php under application/config/config.php , you need to change two configs there, setting your base_url and deleting the index_page value:转到application/config/config.php config.php下的application/config/config.php ,您需要在那里更改两个配置,设置base_url并删除index_page值:

$config['base_url'] = 'your_base_url';
$config['index_page'] = '';

Then in you FCPATH create a .htaccess file with the following content:然后在你的FCPATH创建一个包含以下内容的.htaccess文件:

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

Now everything should work just fine (unless you are using lamp cause in this case your need to do some extra steps in your apache configurations).现在一切都应该正常工作(除非您在这种情况下使用lamp原因,您需要在apache配置中执行一些额外的步骤)。

thanks for your response.感谢您的答复。 i always do that, but not worked and i dont understand why.... i'm on apache2 / rewrite module enable我总是这样做,但没有用,我不明白为什么......我在 apache2/rewrite 模块启用

i modify the virtual host too AllowOverride All我也修改了虚拟主机 AllowOverride All

    Options Indexes FollowSymLinks MultiViews

    DirectoryIndex index.html index.phtml index.php
    php_admin_flag engine On
     AddType application/x-httpd-php .php .phtml .php3
    </Directory>

This will be helpful on lamp这对灯有帮助


Put this code on your .htaccess file将此代码放在您的.htaccess file

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

open打开

application/config/config.php

remove index.php删除 index.php

$config['index_page'] = "";

then set然后设置

$config['base_url'] = 'your site base_url';

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

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