2016-11-22 142 views
0

我怎麼可以重寫從如何用htaccess重寫codeigniter中的URL?

http://website.com/index.php/content/index/3 

http://website.com/content/3 

.htaccess文件的URL?

我已經試過這樣:

RewriteRule ^(.*)/(.*)$ index.php/$1/index/$2 [L] 

但沒有奏效。

+0

我試試這個「重寫規則^/$的index.php/$ 1/index/$ 2 [L]「但它不起作用。 –

+0

我已將您的評論添加到問題中。你可以通過解釋什麼不起作用來進一步改進:發生了什麼?你認爲應該發生什麼? –

回答

1

如果其他.htaccess文件尚未創建,請在項目根目錄中創建.htaccess文件。 將以下代碼複製粘貼到其中。

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

使用以下模式:

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^([\w-]+)/([\w-]+)$ index.php/$1/index/$2 [L] 
</IfModule> 
0

嘗試以下東西:(*)(。*)

<IfModule mod_rewrite.c> 

Options +FollowSymLinks 
RewriteBase/
RewriteEngine On 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 
#Send request via index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L] 

</IfModule>