Apache 取出[R:重定向]后mod_重写不起作用

Apache 取出[R:重定向]后mod_重写不起作用,apache,.htaccess,codeigniter,mod-rewrite,Apache,.htaccess,Codeigniter,Mod Rewrite,我正在使用CodeIgniter,并试图重写url,以便于搜索引擎优化。 目的是 http://localhost/FOR-SEO/item/view/id -> to -> http://localhost/item/view/id 只是想出去走走 我尝试添加htaccess,如下所示: RewriteRule ^(.*)/item/view/(.*)$ /item/view/$2 [R,L] 所以它变成了 RewriteEngine on RewriteCond $1 !^(

我正在使用CodeIgniter,并试图重写url,以便于搜索引擎优化。 目的是

http://localhost/FOR-SEO/item/view/id
-> to -> http://localhost/item/view/id
只是想出去走走

我尝试添加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]
这有什么错,我有没有更好的解决办法来让它发挥作用

非常感谢

我认为这是因为[R]在这种情况下,基础已经设置好,路径被附加到重定向端点的基础url

因此,对于[R],请求http://example.com/index.php/item/view/2,将附加/index.php/item/view/2http://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

您可以在日志中清楚地看到多个重定向:

。。。 [rid100993a50/首字母/重读1]。。。 [rid100991828/首字母/重读2]。。。


那么你有没有办法得到同样的结果?如果它与[R]一起工作,为什么不离开它呢?有什么问题?什么是理想的结果?我想做一个搜索引擎优化友好的网址。将[R]放置在结果中,然后更改url。但我希望搜索引擎看到我的掩码url。请尝试在“重写:重写规则^.*/item/view/*$”中使用完整urlhttp://example.com/item/view/$2[L]