1
Dylian
Change the redirect_header() url.
  • 2009/12/23 8:43

  • Dylian

  • Friend of XOOPS

  • Posts: 237

  • Since: 2007/7/21


I have a little problem with rewriting my urls from http://www.dylian.eu to en.dylian.eu This is what IS working: xlanguage module installed; .htaccess rewrite of en.dylian.eu to http://www.dylian.eu/?lang=english | http://www.dylian.eu/?something=somethingelse[edit] & lang = english (without the spaces) (why does the textsanitizer remove the & symbol if something is put right next to it??)[/edit] smarty plugin to rewrite all url's in smarty templates to the new one where needed. And this is what isn't working: preload file to rewrite the url of redirect header(). These are the files i use (removed all the irelevant stuff...): /domainroot/.htaccess (Working)
RewriteEngine On 

rewriteCond 
%{REQUEST_URI} ^(.*)?
RewriteRule ^en.dylian.eu/(.*)$ www.dylian.eu/$1?=english [QSA,L]

rewriteCond %{REQUEST_URI} !^(.*)?
RewriteRule ^en.dylian.eu/(.*)$ www.dylian.eu/$1?lang=english [QSA,L]
/domainroot/www.dylian.eu/class/smarty/xoops_plugins/outputfilter.xoLangRewriteModule.php (Working / Based on the xoRewriteModule)
include_once XOOPS_ROOT_PATH '/Frameworks/smarty/xoSmartyFunctions.php';

function 
smarty_outputfilter_xoLangRewriteModule$source, &$smarty ) {
    if(
$_GET['lang'] == "english"){
        
$GLOBALS['xoopsLogger']->addExtra("plugin smarty for XOOPS => xoLangRewriteModule ""Loaded");
        
$newurl str_replace("www." "en." XOOPS_URL);
        
$source str_replace(XOOPS_URL $newurl $source);
    }

    return 
$source;
}
?>
/domainroot/www.dylian.eu/modules/xHacks/preloads/core.php (Not fully working)
defined('XOOPS_ROOT_PATH') or die('Restricted access');

class 
xHacksCorePreload extends XoopsPreloadItem
{
    function 
eventCoreHeaderAddmeta($args// Working
    
{
        
$GLOBALS['xoopsTpl']->load_filter('output''xoLangRewriteModule');
    }
    
    function 
eventCoreIncludeFunctionsRedirectheader($args){ // Not working
        // $args[0] Contains the url variable (The URL to redirect to) 
        
if($_GET['lang'] == "english"){
            
$GLOBALS['xoopsLogger']->addExtra("plugin preload for XOOPS => xoLangRewriteModule ""Loaded");
            
$newurl str_replace("www." "en." XOOPS_URL);
            
$args[0] = str_replace(XOOPS_URL $newurl $args[0]);
            
//redirect_header($args[0], $args[1], $args[2], $args[3], $args[4]);
            //exit();
        
}
    } 
}
?>
As you can see i tried to fix this be just calling the function again but this caused my pages to never stop loading. Does someone know how to fix this? Greets Dylian.

2
Dylian
Re: Change the redirect_header() url.
  • 2009/12/23 22:31

  • Dylian

  • Friend of XOOPS

  • Posts: 237

  • Since: 2007/7/21


*** BUMP ***

Please, i really don't know how to fix this...

Greets Dylian.

3
ghia
Re: Change the redirect_header() url.
  • 2009/12/24 2:47

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


I don't think you can do such thing easily with the standard rewrite. I think you must do that by a rewrite that calls a PHP file.
You have two cases: links with and without queries. The lang query to add is different
http://www.dylian.eu/ => http://www.dylian.eu/?lang=english
and
http://www.dylian.eu/?something=somethingelse => http://www.dylian.eu/?something=somethingelse&lang=english

4
Dylian
Re: Change the redirect_header() url.
  • 2009/12/24 11:47

  • Dylian

  • Friend of XOOPS

  • Posts: 237

  • Since: 2007/7/21


sorry, posted the wrong .htaccess file (the one i posted before wasn't copied because my real .htacess file is way to long to post here).

But i fixed the problem you mentioned by checking if a url contains ? and if it does then do "(url) ? ... = ... & lang = english" (without the spaces...).

My .htaccess rules: (the rewrite conditions do the ? and & switch)
[edit]Removed...[/edit]


[edit]
The code window messes up my code....
Please go to http://temp.dylian.eu/langRewrite.txt to see the correct .htaccess
[/edit]

[edit2]
Ok it wasn't the code window but the text sanitizer i think...
BTW You can already see the rewrite working if you go to http://en.dylian.eu/ (but you'll get redirected to http://www.dylian.eu if you go to a page that uses the redirect_header(); function)
[/edit2]


This works and doesn't create any problems for me, the only problem i have is that my redirect_header(); preload doesn't work.

Greets Dylian.

5
trabis
Re: Change the redirect_header() url.
  • 2009/12/26 15:53

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Hi Dylian,
It looks like you want to change the url argument of the function and return the execution back to the function. That can only be possible if the 'url' is passed by reference. Changing:
$xoopsPreload->triggerEvent('core.include.functions.redirectheader', array($url$time$message$addredirect$allowExternalLink));

Into:
$xoopsPreload->triggerEvent('core.include.functions.redirectheader', array(&$url$time$message$addredirect$allowExternalLink));


While this change is not made in the core, you should copy the redirect_header function and paste it inside your preload.

6
Dylian
Re: Change the redirect_header() url.
  • 2009/12/27 0:27

  • Dylian

  • Friend of XOOPS

  • Posts: 237

  • Since: 2007/7/21


@Trabis, thanks a lot for reacting.

But strange enough both ways don't seem to fix the problem (i guess i'm doing something wrong).

1. I added the & symbol to url variable. But this didn't change anything. (As far as i noticed, my pages still redirect to www. instead of en.)

2. I changed $args[0] = ... ; to $url = ... ; and added the content (exept the preload part) of the redirect_header(); function to my preload. And this causes my pages (where the redirect_header(); function is called) to never stop loading. (Just like calling the redirect_header(); function again did before).

Do you know what the problem is?
And if you don't know it i think i'll just hack mainfile.php to check if $_GET['lang'] contains english and if it does then define the XOOPS url as en.dylian.eu and otherwise as http://www.dylian.eu .

Greets Dylian.

Login

Who's Online

181 user(s) are online (102 user(s) are browsing Support Forums)


Members: 0


Guests: 181


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits