2013-03-03 63 views
0

我抨击我的头对着键盘,无法弄清楚这个问题,并且无法在google上得到答案。301重定向类别/ category/index.php到category/category.html

我有一堆旧的网址我想301重定向。例如父/子* 的index.php *必须成为母公司* /child.html *

这是我写:

RewriteCond %{REQUEST_URI} /index.php$ 
RewriteCond %{QUERY_STRING} ^$ 
RewriteRule ^(.*)/index.php$ $1.html? [L,R=301] 

没有发送到索引请求.php所以这就是为什么我让第二个条件为空。 如果我在this Rewrite rule tester上测试它,它会失败,除非我手动填充request_URI值(请参阅上面的链接)

我将非常感谢任何帮助。如果我解决不了,我将不得不手动做Redirect 301 oldurl newurl,这将需要很长时间!

+0

我需要添加,这是为了joomla 2.5迁移,所以/administrator/index.php必须仍然正常运行 – Kalemanzi 2013-03-03 18:02:15

+0

似乎工作使用*重写规则测试器*链接到。哪里不对?考虑发布剩下的'.htaccess'指令,这些规则的执行顺序可能会有问题。 – kjetilh 2013-03-03 19:18:02

回答

0

你可以在根目录中的一个.htaccess文件试试这个:

Options +FollowSymlinks -MultiViews 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)/index\.php/? [NC] 
RewriteRule .*    /%1/%2.html    [R=301,L] 

地图默默

http://example.com/parent/child/index.php

http://example.com/parent/child.html

字符串parent和假设是可变的,而index.php被假定为固定的。

对于无声映射,替换[R = 301,L]与[L]

这适用于一个真实服务器。但是,您可以在没有%{REQUEST_FILENAME}条件的情况下对其进行测试here,但不支持该测试站点。