2013-03-25 79 views
1

我使用CodeIgniter,並試圖重寫URL友好的SEO。 的目的是......mod_rewrite後不工作[R:重定向]出

http://localhost/FOR-SEO/item/view/id 
-> to -> http://localhost/item/view/id 

(只是想離開,SEO出)

我嘗試添加的htaccess如下,

RewriteRule ^(.*)/item/view/(.*)$ /item/view/$2 [R,L] 

所以它成爲...

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

它工作正常,但在我拿[R]它顯示404錯誤未找到。

我試圖檢查重寫日誌,但一切是一樣的對於用[R],沒有[R]

這裏的日誌,[R](工作)

[rid#1009868a0/initial] (1) [perdir /Applications/MAMP/htdocs/himaparn/] escaping http://localhost:8888/item/view/2 for redirect 
[rid#1009868a0/initial] (1) [perdir /Applications/MAMP/htdocs/himaparn/] redirect to http://localhost:8888/item/view/2 [REDIRECT/302] 
[rid#10098a8a0/initial] (1) [perdir /Applications/MAMP/htdocs/himaparn/] internal redirect with /index.php/item/view/2 [INTERNAL REDIRECT] 
[rid#100984da8/initial/redir#1] (1) [perdir /Applications/MAMP/htdocs/himaparn/] pass through /Applications/MAMP/htdocs/himaparn/index.php 
[rid#1009978a0/subreq] (1) [perdir /Applications/MAMP/htdocs/himaparn/] internal redirect with /index.php/item/view/2 [INTERNAL REDIRECT] 

這裏是沒有[R]的日誌,(不工作)

[localhost/sid#100813108][rid#10098f8a0/initial] (1) [perdir /Applications/MAMP/htdocs/himaparn/] internal redirect with /item/view/2 [INTERNAL REDIRECT] 
[localhost/sid#100813108][rid#100993a50/initial/redir#1] (1) [perdir /Applications/MAMP/htdocs/himaparn/] internal redirect with /index.php/item/view/2 [INTERNAL REDIRECT] 
[localhost/sid#100813108][rid#100991828/initial/redir#2] (1) [perdir /Applications/MAMP/htdocs/himaparn/] pass through /Applications/MAMP/htdocs/himaparn/index.php 
[localhost/sid#100813108][rid#1009978a0/subreq] (1) [perdir /Applications/MAMP/htdocs/himaparn/] internal redirect with /index.php/item/view/2 [INTERNAL REDIRECT] 

這是什麼錯誤,我有什麼不對的做法,使我的工作?

非常感謝!

回答

0

我認爲這是因爲[R]forces an external redirect在這種情況下,基地已經設置和路徑被附加到重定向端點的基地址。

所以,用[R],以http://example.com/index.php/item/view/2的請求,/index.php/item/view/2將被追加到http://example.com/離開你http://example.com/index.php/item/view/2

沒有[R]您得到的內部重定向。這將附加/index.php/item/view/2到請求。因此請求http://example.com/index.php/item/view/2將使您與http://example.com/index.php/item/view/2/index.php/item/view/2掛鉤你一個404

你可以很清楚地看到日誌中多次重定向:

...
[擺脫#100993a50 /開始/ REDIR#1] ...
[擺脫#100991828 /開始/ redir#2] ...
...

+0

那麼你有什麼想法做出同樣的結果嗎? – chaintng 2013-03-26 00:47:36

+0

如果它與'[R]'一起使用,爲什麼不離開它?問題是什麼?期望的結果是什麼? – stormdrain 2013-03-26 13:17:04

+0

我想製作一個seo友好的網址。把[R]更改URL的結果。但我想讓搜索引擎看到我的面具網址。 – chaintng 2013-03-26 14:43:56