CodeIgniter'daki index.php yönlendir

5 Cevap php

Ben CodeIgniter uygulama oluşturulmuş ve şimdi ben onsuz URL'lerin index.php ile adresler yönlendirmek çalışıyorum.

. Benim geçerli htaccess olduğunu:

RewriteEngine On
RewriteBase /

# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

# Enforce www
# If you have subdomains, you can add them to 
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ http://www.plugb.com/$1 [L,R=301]

# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Tek sorun, aynı sayfa ve index.php olmadan erişilebilir olmasıdır.

Örneğin:

http://www.plugb.com/index.php/games/adventure-rpg

ve

http://www.plugb.com/games/adventure-rpg

Index.php URL'leri yeniden yönlendirmek için bir yolu var mı?

Thank you, Gabriel.

5 Cevap

Son kuralın önce ekleyin:

RewriteBase /    
RewriteCond %{HTTP_HOST} !=""
RewriteRule ^index.php(/.*)?$ http://%{HTTP_HOST}$1 [R=301]

veya erişimi reddetmek için:

RewriteRule ^index.php(/.*)?$ - [R=404]

CodeIgniter wiki documentation tam bu davranışı başarmak için nasıl açıklar.

Bu makale how to take away “index.php” from your CI application URLs açıklıyor. Ancak, yani Index.php URL görünmez olsa bile CI ön denetleyicisi index.php için ihtiyaç kaldırmak DEĞIL, hala / sistemi üzerinde sitenizin üst düzeyde (mevcut olması gerekmektedir / dizin).

Can you try with this? RewriteRule ^(.*)$ index.php/?$1 [L]

Bu yüzden eserleri umuyoruz.

Bunun için bir çözüm ile geldi:

$clean_url = str_replace('index.php','',current_url());
$current_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

if($clean_url!==$current_url)
{
    redirect($clean_url,'location',301);
}

Bu. Htaccess ile değil, ancak denetleyicisi bu sorunu çözebilir. (En azından, o PlugB çalıştı)

Sen 'yönlendirme' URL'LER index.php kod yazmak için ihtiyacım yok.

Application / config / config.php içine gidin ve aşağıdaki değişikliği yapın

$config['index_page'] = "";