簡體   English   中英

從 url codeigniter 中刪除 index.php

[英]Remove index.php from url codeigniter

我和很多人有同樣的問題,要從 codeigniter 的 url 中刪除 index.php。

我總是從先前的答案中完成所有響應,但我總是可以使用 index.php 訪問 url

這個 url 工作: https://www.domaine.tld/Test但我可以訪問: https://www.domaine.tld/index.php/Test (也工作)

我的網站中沒有包含 index.php 的任何鏈接,但我的問題是如何使用 index.php 重定向 url 以防止重復內容。

感謝您的回答。

Codeigniter 有漂亮的文檔。你現在可以在 Codeigniter user_guide 中找到所有與 Codeigniter 相關的東西來解決你的問題在 root 中創建.htaccess文件並粘貼以下代碼

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

然后也刪除index.php

application/config/config.php

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

更改為

$config['index_page'] = '';

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

把它放在你的.htaccess

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

打開 config.php 並執行以下替換

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

$config['index_page'] = ""

轉到application/config/config.php config.php下的application/config/config.php ,您需要在那里更改兩個配置,設置base_url並刪除index_page值:

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

然后在你的FCPATH創建一個包含以下內容的.htaccess文件:

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

現在一切都應該正常工作(除非您在這種情況下使用lamp原因,您需要在apache配置中執行一些額外的步驟)。

感謝您的答復。 我總是這樣做,但沒有用,我不明白為什么......我在 apache2/rewrite 模塊啟用

我也修改了虛擬主機 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>

這對燈有幫助


將此代碼放在您的.htaccess file

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

打開

application/config/config.php

刪除 index.php

$config['index_page'] = "";

然后設置

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM