e107inc / e107

e107 Bootstrap CMS (Content Management System) v2 with PHP, MySQL, HTML5, jQuery and Twitter Bootstrap. Issue Discussion Room: https://gitter.im/e107inc/e107
https://e107.org
GNU General Public License v3.0
322 stars 214 forks source link

weird SEF behaviour #5088

Open 3l3ktr0n opened 1 year ago

3l3ktr0n commented 1 year ago

I'm encountering some weird SEF behaviour. Having SEF enabled some urls don't work anymore. For example (SEF not enabled) - review.php?id=7&review=59

Array
(
    [game_sef] => test-6
    [review_id] => 59
    [review_title] => test
    [review_user_id] => 1
)
C:\wamp64\www\test\e107_plugins\games\review.php:21:
array (size=4)
  'game_sef' => string 'test-6' (length=6)
  'review_id' => string '59' (length=2)
  'review_title' => string 'test' (length=4)
  'review_user_id' => string '1' (length=1)
Array
(
    [game_id] => 7
    [game_sef] => test-6
    [review_id] => 59
    [review_sef] => test
)
/test/e107_plugins/games/review.php?id=7&review=59
C:\wamp64\www\test\e107_plugins\games\review.php:41:boolean true

everything is working fine now SEF enabled - reviews/59/test/edit

C:\wamp64\www\test\e107_plugins\games\review.php:21:boolean false
Array
(
    [game_id] => 7
    [game_sef] => 
    [review_id] => 
    [review_sef] => 
)
/test/e107_plugins/games/review.php?id=7&review=
C:\wamp64\www\test\e107_plugins\games\review.php:41:boolean false

but when I change the url to - reviews/59/tes/edit - then it works

Array
(
    [game_sef] => test-6
    [review_id] => 59
    [review_title] => test
    [review_user_id] => 1
)
C:\wamp64\www\test\e107_plugins\games\review.php:21:
array (size=4)
  'game_sef' => string 'test-6' (length=6)
  'review_id' => string '59' (length=2)
  'review_title' => string 'test' (length=4)
  'review_user_id' => string '1' (length=1)
Array
(
    [game_id] => 7
    [game_sef] => test-6
    [review_id] => 59
    [review_sef] => test
)
/test/games/7/test-6/reviews/59/test
C:\wamp64\www\test\e107_plugins\games\review.php:41:boolean true

Sorry for my bad explanation...

$gameID = (isset($_GET['id']) && is_numeric($_GET['id'])) ? abs(round($_GET['id'])) : 0;

$data = array(
     'game_id'        => $gameID,
     'game_sef'      => $this->var['game_sef'], 
     'review_id'      => $this->var['review_id'], 
     'review_sef'     => eHelper::title2sef($this->var['review_title'], 'dashl'),
     'edit'               => $action = 'edit'
); 
$url = e107::url('games', 'editreview', $data);
Jimmi08 commented 1 year ago

Where is your e_url.php file? It is not in your repo. Or what is your config for 'editreview' key?

3l3ktr0n commented 1 year ago
$config['editreview'] = array(
            'alias'         => 'games',
            'regex'         => '^{alias}/([0-9]+)/([^/]+)/reviews/([0-9]+)/([^/]+)/([^/]+)/?$',
            'sef'           => '{alias}/{game_id}/{game_sef}/reviews/{review_id}/{review_sef}/{edit}',
            'redirect'      => '{e_PLUGIN}games/review.php?id=$1&review=$3&action=$5'
        );
3l3ktr0n commented 1 year ago

and this behaviour is present only in some reviews not all

Jimmi08 commented 1 year ago

No idea. Sorry. From my experience, some other rewrite is used before your own, but your regex is so specific that I don't know. Last time when this happened to me I debugged application.php line by line to find the reason.
And there is some debug to get displayed what rewrite was used but I don't remember it.

3l3ktr0n commented 1 year ago

for some reason games/7/test-6/reviews/59/test/edit gives me

e_URL in games with key: newreview matched ^games/([0-9]+)/([^/]+)/reviews/([^/]+)/?$ and included: ./e107_plugins/games/review.php with $_GET:
Array
(
    [id] => 7
    [action] => 59edit
)

it's looking for the wrong key for no known reason....................... but changing 'review_sef' => eHelper::title2sef($this->var['review_title'], 'dashl') to whatever gets me

e_URL in games with key: editreview matched ^games/([0-9]+)/([^/]+)/reviews/([0-9]+)/([^/]+)/([^/]+)/?$ and included: ./e107_plugins/games/review.php with $_GET:
Array
(
    [id] => 7
    [review] => 59
    [action] => edit
)
3l3ktr0n commented 1 year ago
        $config['newreview'] = array(
            'alias'         => 'games',
            'regex'         => '^{alias}/([0-9]+)/([^/]+)/reviews/([^/]+)/?$',
            'sef'           => '{alias}/{game_id}/{game_sef}/reviews/{new}',
            'redirect'      => '{e_PLUGIN}games/review.php?id=$1&action=$3'
        );
Jimmi08 commented 1 year ago

In this case - only your real URL and 'regex' value from your config file is important. Use https://regex101.com/ why for your URL is wrong regex used (you need to add backslashes there)
Maybe reorder them. games/7/test-6/reviews/59/test/edit and regex from 'newreview' - is valid

Do you use it before editreview?
I don know how your URL looks after "but changing ... to whatever gets me" not to pass this regex and use next one. image

3l3ktr0n commented 1 year ago

but 'newreview' isnt using backslashes also

Jimmi08 commented 1 year ago

but 'newreview' isnt using backslashes also

Sorry, misunderstanding - I meant that if you want to use that regex tool, you need to add backslashes, e_url doesn't need them.

3l3ktr0n commented 1 year ago

In this case - only your real URL and 'regex' value from your config file is important. Use https://regex101.com/ why for your URL is wrong regex used (you need to add backslashes there) Maybe reorder them. games/7/test-6/reviews/59/test/edit and regex from 'newreview' - is valid

Do you use it before editreview? I don know how your URL looks after "but changing ... to whatever gets me" not to pass this regex and use next one. image

I have been using it from time to time and haven't noticed any erros - although I don't really understand how the regex101.com debugger works

3l3ktr0n commented 1 year ago

I'm at my wits. I still haven't figured out how to fix it or what exactly causes it. I have singled out that for some reason the right url games/7/test-6/reviews/59/test/edit - 'test' seems to be responsible for the $_GET that identifies the review_id not to get the id for an unknown reason

3l3ktr0n commented 1 year ago

games/7/test-6/reviews/59/test/edit

e_URL in games with key: newreview matched ^games/([0-9]+)/([^/]+)/reviews/([^/]+)/?$ and included: ./e107_plugins/games/review.php with $_GET:
Array
(
    [id] => 7
    [action] => 59edit
)

games/7/test-6/reviews/59/whatever/edit

e_URL in games with key: editreview matched ^games/([0-9]+)/([^/]+)/reviews/([0-9]+)/([^/]+)/([^/]+)/?$ and included: ./e107_plugins/games/review.php with $_GET:
Array
(
    [id] => 7
    [review] => 59
    [action] => edit
)
3l3ktr0n commented 11 months ago

no idea how to reproduce it for others but I'm still facing this problem

was thinking maybe eHelper::title2sef is causing this.. changed straight to the row from database for sef.. nothing changed.. same same tried changing the value in the database.. still not working

I cant figure out if the mistake is in e107 or me but it's kinda game breaking currently

Moc commented 11 months ago

This is likely a mistake in your e_url.php file, not in core.

Can you please post:

3l3ktr0n commented 11 months ago
<?php
/*
 * e107 Bootstrap CMS
 *
 * Copyright (C) 2008-2015 e107 Inc (e107.org)
 * Released under the terms and conditions of the
 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
 * 
 * IMPORTANT: Make sure the redirect script uses the following code to load class2.php: 
 * 
 *  if (!defined('e107_INIT'))
 *  {
 *      require_once("../../class2.php");
 *  }
 * 
 */

if(!defined('e107_INIT'))
{
    exit;
}

// v2.x Standard  - Simple mod-rewrite module. 

class games_url // plugin-folder + '_url'
{

    function config() 
    {
        $config = array();

        $config['games'] = array(
            'alias'         => 'games',
            'regex'         => '^{alias}\/?([\?].*)?\/?$',
            'sef'           => '{alias}',
            'redirect'      => '{e_PLUGIN}games/games.php$1'            
        );

        $config['game'] = array(
            'alias'         => 'games',
            'regex'         => '^{alias}/([0-9]+)/([^/]+)/?$',
            'sef'           => '{alias}/{game_id}/{game_sef}',
            'redirect'      => '{e_BASE}game.php?id=$1'
        );

        $config['navigation'] = array(
            'alias'         => 'games',
            'regex'         => '^{alias}/([0-9]+)/([^/]+)/([^/]+)/?$',
            'sef'           => '{alias}/{game_id}/{game_sef}/{page}',
            'redirect'      => '{e_BASE}game.php?id=$1&page=$3'
        );

        $config['review'] = array(
            'alias'         => 'games',
            'regex'         => '^{alias}/([0-9]+)/([^/]+)/reviews/([0-9]+)/([^/]+)/?$',
            'sef'           => '{alias}/{game_id}/{game_sef}/reviews/{review_id}/{review_sef}',
            'redirect'      => '{e_PLUGIN}games/review.php?id=$1&review=$3'
        );

        $config['newreview'] = array(
            'alias'         => 'games',
            'regex'         => '^{alias}/([0-9]+)/([^/]+)/reviews/([^/]+)/?$',
            'sef'           => '{alias}/{game_id}/{game_sef}/reviews/{new}',
            'redirect'      => '{e_PLUGIN}games/review.php?id=$1&action=$3'
        );

        $config['editreview'] = array(
            'alias'         => 'games',
            'regex'         => '^{alias}/([0-9]+)/([^/]+)/reviews/([0-9]+)/([^/]+)/([^/]+)/?$',
            'sef'           => '{alias}/{game_id}/{game_sef}/reviews/{review_id}/{review_sef}/{edit}',
            'redirect'      => '{e_PLUGIN}games/review.php?id=$1&review=$3&action=$5'
        );

        return $config;
    }

}

?>

games/2/test-2/reviews/29/1234567890/edit - correct

games/7/test-6/reviews/59/test/edit - correct but fails games/7/test-6/reviews/59/whatever/edit - for some reason changing {review_sef} makes it work...

3l3ktr0n commented 10 months ago

have been trying to get help from AI. not really helpful well.. for some reason

        $data = array(
            'game_id'       => $gameID,
            'game_sef'      => $this->var['game_sef'],
            'review_id'     => $this->var['review_id'],
            'review_sef'    => $this->var['review_sef'],
            'edit'              => $action = 'edit'
        );
        $url = e107::url('games', 'editreview', $data);

when fetching review_sef from the database it still fails when the value is 'test' but when i change it for example 'test1' then it works and currently having this problem with a single review