2014-07-15 130 views
1

不工作我使用PHP和Apache服务器的工作,我想重写sites/all/themes/chap2014/fpd/gift.phpfdp/giftsites/all/themes/chap2014/fpd/another.phpfdp/another 正是我想要做到这一点重写URL在PHP

重写sites/all/themes/chap2014/fpd/*.phpfpd/*

重写模式启用,我在.htacess文件中尝试下面的代码。

RewriteEngine on 
RewriteRule ^fpd/?$ sites/all/themes/chap2014/fpd/$1.php 

但是什么都没有发生,实现这个目标的正确方法是什么?

得到任何帮助,

回答

2

你需要URI对URI模式的LHS第一组和捕捉部分,你可以在RHS使用$1$2等之前。

RewriteEngine on 

RewriteRule ^fpd/([^/]+)/?$ /sites/all/themes/chap2014/fpd/$1.php [L,NC] 

PS:在你的问题,你都用了fpdfdp。不知道哪一个是对的。

+0

我尝试这一点,但什么都没有发生在 重写规则^ FPD /([^ /] +)/ $ 'RewriteEngine叙述? /sites/all/themes/chap2014/fpd/$1.php [L,NC]' – zhilevan

+0

我测试你的规则在http://martinmelin.se/rewrite-rule-tester/ 与此网址'网站/所有/主题/ chap2014/fpd/tshirt.php'但被告知不匹配 – zhilevan

+0

1.切勿在该网站上测试,因为它不可靠。 2.你需要输入你的URI为'http:// example.com/fpd/tshirt.php',它将被内部转发到'http://example.com/sites/all/themes/chap2014/fpd/tshirt .php' – anubhava

2

试试这个:

RewriteRule ^fpd/(.+)$ sites/all/themes/chap2014/fpd/$1.php

你可能要排除的/符号,如果是这样,然后用[^/]+更换.+

您必须将要放入的零件放入变量(),每个封闭零件将放入$ 1,$ 2,$ 3等等。

而且,这里是一个很好的工具来测试你重写规则:

http://martinmelin.se/rewrite-rule-tester/

+0

我尝试在你建议的测试,网址为“sites/all/themes/chap2014/fpd/tshirt.php”,回报不匹配, – zhilevan

+0

@zhilevan,它不应该返回任何东西。在测试仪中键入'fpd/tshirt',你会看到它重写为'sites/all/themes/chap2014/fpd/tshirt.php'。毕竟,这就是域名后面的URL –