2017-01-17 15 views
0

の.htaccessでサブドメインの後のindex.phpを削除します。CodeIgniterの:私の現在のURLは次のようになり

http://www.example.com/testdesign/index.php/tasks 

そして、私はそれがにリダイレクトする必要があります。

http://www.example.com/testdesign/tasks 

マイcodeignitorルートの.htaccessファイルが含まれています

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] 
    RewriteCond %{REQUEST_URI} !/system/.* [NC] 
    RewriteRule (.?)index\.php/(.*) /$1$2 [R=301,NE,L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 

mod_rewriteが自分のApacheサーバーで有効になっています。私の設定ファイルで

$config['index_page'] = ''; 
$config['uri_protocol'] = 'REQUEST_URI'; 

私はローカルホストからそれを実行すると、それはこのように私を示しています

http://www.example.com/tasks 

しかし、私はだけでなく、サブドメインはindex.php削除します。

私はそれが非常に小さな問題かもしれないことは知っていますが、私はエラーを見つけることができません。

私はそれについて適切な提案をしますか?

どんな種類のヘルプが高く評価されます。

ありがとうございます。

+0

多分あなたはこれを読むべきです:[http:// stackoverflo w.com/a/41364059/6054930(http://stackoverflow.com/a/41364059/6054930)。 – ShutUpMagda

+0

@ShutUpMagda、私はすでにこの文書を読んで同じものを適用していますが、動作しません。 –

+0

私はまた、 'base_url()'の代わりに 'site_url()'を使うことがこの問題の原因の一つであることにも気付きました。 – ShutUpMagda

答えて

0

ただ、これを試してみてください:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /testdesign 

# Removes access to the system folder by users. 
RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

# Prevents user access to the application folder 
RewriteCond %{REQUEST_URI} ^application.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

# 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] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    ErrorDocument 404 /index.php 
</IfModule> 

それはあなたがあなたのuri_protocolとBASE_URLを設定しなかった場合でも動作します。

+0

同じURLを返していません。 –

+0

.htaccessファイルを置く場所は? –

+0

.htaccessファイルを次のようにルートディレクトリに置きます。/ application/system index.php .htaccess –

0

このようにしてください。あなたの.htaccessファイル

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] 
    RewriteCond %{REQUEST_URI} !/system/.* [NC] 
    RewriteRule (.?)index\.php/(.*) /$1$2 [R=301,NE,L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)/testdesign$ index.php/$1 [L] 
</IfModule> 

OR

で設定$config['base_url']='http://www.example.com/testdesign/'

その後 実行www.example.com/testdesign/tasks

+0

@hikamt、動作していないので、次のようなURLを返します:www.example.com/tasks –

+0

base_urlを設定した場合。 htaccess 'RewriteRule ^(。*)$ index.php/$ 1 [L]' –

+0

まだ動作していません。このようなレスポンスはwww.example.com/tasksにあります。 –

0

かわりsite_url()base_url()を使用するようにしてください。あなたの書き換え構成が正しく設定されていても、site_url()を使用している場合、index.phpファイルが含まれます。

はドキュメントもっと見る:site_urlr()base_url()

をあなたはまた、あなたののconfig/config.phpの中index_page設定

/* 
|-------------------------------------------------------------------------- 
| Index File 
|-------------------------------------------------------------------------- 
| 
| Typically this will be your index.php file, unless you've renamed it to 
| something else. If you are using mod_rewrite to remove the page set this 
| variable so that it is blank. 
| 
*/ 
$config['index_page'] = 'index.php'; 
+0

私の設定ファイルでは、これは既に空白のindex_pageです:$ config ['index_page'] = ''; –

0

があなたの.htaccessにコードの下に置き換え空白のままにすべきですコード

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 
関連する問題