2017-01-17 42 views
0

我當前的URL看起來像這樣:笨:在.htaccess子域後刪除的index.php

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

我也注意到使用'site_url()'而不是'base_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

不工作並返回相同的網址。 –

+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,不工作,並得到像這樣的返回網址:www.example.com/tasks如果你設置base_url –

+0

。在htaccess中'RewriteRule ^(。*)$ index.php/$ 1 [L]' –

+0

還沒有正常工作,仍然得到相同的迴應,如下所示:www.example.com/tasks –

0

你應該嘗試使用base_url(),而不是site_url()。請參閱,即使您的重寫配置設置正確,如果您使用site_url()index.php文件將被包括在內。

查看更多在docs:site_urlr()base_url()

你也應該留空index_page配置在的config/config.php文件

/* 
|-------------------------------------------------------------------------- 
| 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>