2013-03-25 72 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