[英]Redirect to route with Apache .htaccess
I want to redirect from my .htaccess to a specific route (i use Zend Framework but it's the same for every framework i guess). 我想从我的.htaccess重定向到特定路由(我使用Zend Framework,但我猜每个框架都相同)。
Here is my .htaccess: 这是我的.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=/?(.*)$
RewriteRule ^(.*)$ /snapshot/%1? [NC,L]
This does not work. 这是行不通的。 Note: the snapshot
folder does not exists. 注意: snapshot
文件夹不存在。
But if i replace the last line by : 但是如果我将最后一行替换为:
RewriteRule ^(.*)$ http://my-site.com/snapshot/%1? [NC,L]
It works... The second works but the redirect url is visible, and i don't want that. 它有效...第二个有效,但是重定向URL是可见的,我不想要那样。
What can i do for make the first example working? 为了使第一个示例正常工作,我该怎么做?
I have a solution but it does not require mod_rewrite. 我有一个解决方案,但不需要mod_rewrite。 You have to edit your index.php a little bit. 您必须编辑一下index.php。 Just after $application->bootstrap ();
就在$application->bootstrap ();
and before $application->run ();
在$application->run ();
add this snippet. 添加此代码段。
$application->bootstrap ();
if (preg_match ('~_escaped_fragment_=(.*)~', $_SERVER ['QUERY_STRING'], $match))
{
$frontcontroller = $application->getBootstrap()->FrontController;
$request = new Zend_Controller_Request_Http('http://your.site.com/controller/'.$match[1]);
$frontcontroller->setRequest($request);
}
$application->run ();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.