我使用 CodeIgniter 并试图重写 url 以实现对 SEO 友好。目的是...
http://localhost/FOR-SEO/item/view/id
-> to -> http://localhost/item/view/id
(只是想把 FOR-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]
这有什么问题,我有更好的解决方案来完成这项工作吗?
非常感谢!