我需要建议htaccess规则解码url字符串,例如:
实际页面是
http://www.mycarhelpline.com/index.php?option=com_latestnews&view=detail&n_id=953&Itemid=10
但是,Google将其作为
缓存在Google中http://www.mycarhelpline.com/index.php%3Foption%3Dcom_latestnews%26view%3Ddetail%26n_id%3D953%26Itemid%3D10
解码后的字符串将导致更正的网址
我很抱歉因为完全没有意识到htaccess规则,因此没有粘贴代码。是否有任何htaccess规则可以删除转义字符并通过重定向导致正确的网址
更新 就像给出的一样 https://docs.joomla.org/J2.5:Developing_a_MVC_Component/Basic_backend
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import joomla controller library
jimport('joomla.application.component.controller');
// Get an instance of the controller prefixed by HelloWorld
$controller = JController::getInstance('HelloWorld');
// Get the task
$jinput = JFactory::getApplication()->input;
$task = $jinput->get('task', "", 'STR' );
// Perform the Request task
$controller->execute($task);
// Redirect if set by the controller
$controller->redirect();
我应该在获取任务时添加这一行 - 它是否需要
$url = urldecode($jinput->get('url', '', 'string'));
最终守则是
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
require_once( JPATH_COMPONENT.DS.'pager.cls.php' );
// import joomla controller library
jimport('joomla.application.component.controller');
// Get an instance of the controller prefixed by HelloWorld
$controller = JController::getInstance('HelloWorld');
// Get the task
$jinput = JFactory::getApplication()->input;
$task = urldecode($jinput->get('task', "", 'STR' ));
// Perform the Request task
$controller->execute($task);
// Redirect if set by the controller
$controller->redirect();
?>
HTACCESS COde - 虽然部分工作正常但未将%3f转换为?
RewriteCond %{QUERY_STRING} ^(.*)\?(.*)$
RewriteRule ^(.*)$ /$1?%1\%3F%2 [L]
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*)$ /$1\%3F%{QUERY_STRING}? [L,NE]
更新 - 最终HTACCESS
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*)$ /$1?%{QUERY_STRING} [L,NE]