2014-02-13 145 views
0

我是新来的.htaccess文件,我一直在试图隐藏从URL扩展.PHP和公用文件夹如何隐藏扩展名和包含的文件夹.htaccess的

换句话说,我要这样:

site.com/public/index.php 

看起来像这样:

site.com/index 

我能单独做两件事情,但我不能在同一时间让他们...

谢谢!

+1

请提供信息你如何设法分开完成这些事情,并且我们可能会建议如何合并它们。 – icabod

+0

RewruteRule(。*)/?的index.php?URL = $ 1然后,您将收到$ _SERVER ['QUERY_STRING']中的查询字符串,并处理'index'以处理它。去尝试一下。将这个应用到.htaccess之后,回显$ _SERVER ['QUERY_STRING']。可能性是你的探索。 –

回答

0

你将需要2条规则。

首先,当您收到site.com/public/index.php的请求,你必须告诉客户通过执行此发送另一个请求site.com/index

RewriteRule ^site\.com/public/index\.php/?$ site.com/index [R=301,L]

的R = 301国旗说,你正在发送HTTP 301'永久移动'标题。当客户收到这个时,他们会发送一个新的请求,但是对于site.com/index

接下来,你需要一个规则来处理请求site.com/index这样的:

RewriteRule ^site\.com/index$ index.php [L]

所以你得到的.htaccess文件应该是这个样子:

RewriteEngine On 

RewriteRule ^site\.com/public/index\.php/?$ site.com/index [R=301,L] 
RewriteRule ^site\.com/index$ index.php [L] 
相关问题