Skip to content

Commit

Permalink
Merge pull request #1 from dschledermann/master
Browse files Browse the repository at this point in the history
[FEATURE] Make it possible to strip certain param.
  • Loading branch information
sorenmalling committed Oct 20, 2014
2 parents f586b1c + de1fd55 commit fd2e785
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
50 changes: 38 additions & 12 deletions class.tx_forcerealurls.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,45 @@ class tx_forcerealurls {

function check($params,$pObj) {
if ($pObj->siteScript && $pObj->config['config']['tx_realurl_enable'] && (
substr($pObj->siteScript, 0, 9) == 'index.php' ||
substr($pObj->siteScript, 0, 1) == '?'
)) {
$baseURL = $pObj->config['config']['baseURL'];
$LD = $pObj->tmpl->linkData($pObj->page,'',$pObj->no_cache,'','',t3lib_div::getIndpEnv('QUERY_STRING'));
$url = $baseURL.$LD['totalURL'];

header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$url);

exit;
substr($pObj->siteScript, 0, 9) == 'index.php' ||
substr($pObj->siteScript, 0, 1) == '?'
)) {
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['forcerealurls']);

// Skipping section
if ($extConf['skip_if_logged_in'] && $GLOBALS['BE_USER']->user) {
return;
}

$query = array();
parse_str(t3lib_div::getIndpEnv('QUERY_STRING'), $query);

if ($extConf['skip_if_no_cache'] && $query['no_cache']) {
return;
}

if ($extConf['skip_if_typeNum'] && $query['type']) {
return;
}

// Stripping section
$strip_params = explode(' ', $extConf['strip_params']);
foreach($strip_params as $strip_param) {
unset ($query[$strip_param]);
}

$queryString = http_build_query($query);

$baseURL = $pObj->config['config']['baseURL'];
$LD = $pObj->tmpl->linkData($pObj->page,'',false,'','',$queryString);
$url = $baseURL.$LD['totalURL'];

header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$url);
header('X-Redirected-By: forcerealurls');

exit;
}
}
}

?>
12 changes: 12 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# cat=basic; type=string; label=Strip params. Strip these parameters if they are present in the query-string (Separate with spaces)
strip_params = no_cache

# cat=basic; type=boolean; label=Logged in skip. Skip redirect if logged in. Check this if you do not want to redirect users that are logged in into the backend.
skip_if_logged_in = 1

# cat=basic; type=boolean; label=No cache skip. Check this if you do not want to get redirects when no_cache is on. This is typically a development setting. This will take precedence over strip_params.
skip_if_no_cache = 0

# cat=basic; type=boolean; label=typeNum skip. Check this if you do not want to get redirects for non-0 typeNum. This is often used if you are doing some sort of AJAX specific pages.
skip_if_typeNum = 1

0 comments on commit fd2e785

Please sign in to comment.