• Resolved GeraldS

    (@geralds)


    I have a list of courses that are stored in a separate database. I’m showing the details of a course with a page /course/ that has the course ID added as a PHP parameter:

    /course/?ID=12345

    The page template then contains code to retrieve the course details and show them on that page.

    To get pretty URLs I have a RewriteRule in my .htaccess:

    RewriteRule ^course/([\d]+) course/?ID=$1

    After Updating to WordPress 5.5 this doesn’t work anymore. Now every request to /course/12345 results in a 301 redirect to /course/, with the ID gone.

    I ruled out Apache as the cause, since the exact same setup works fine when I use it outside of WordPress. Looking through the release notes of 5.5 I noticed that the function redirect_guess_404_permalink() has changed, but commenting out the new code parts didn’t help either, so I guess I’m on the wrong track here.

    Is there any other change in WordPress 5.5 that could result in this change?

    • This topic was modified 4 years, 7 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 7 replies - 1 through 7 (of 7 total)
  • Try:

    RewriteRule ^course/([\d]+) /course/?ID=$1 [L,R=301]

    Thread Starter GeraldS

    (@geralds)

    A redirect is exactly what I don’t want. The URL is supposed to stay /course/12345. And that worked for years until I upgraded WordPress to 5.5.

    Thread Starter GeraldS

    (@geralds)

    I reproduced the problem in a testing environment:

    https://demo.schneidr.de/

    Those two WordPress installations are identical. Extracted WordPress, ran the installation, created the page Course, copied a page template in the template folder, added the RewriteRule to the .htaccess file.

    Both files are available here: https://gist.github.com/schneidr/3b02f094c38ec614a0279dffde5927df
    (of course the RewriteBase differs, but that’s the only difference)

    If you follow the links you’ll see that the 5.4 installation stays at /course/123456/ and the course data is displayed correctly, while on the 5.5 installation a redirect to /course/ occurs.

    Then you can use filter ‘rewrite_rules_array’ and add your own rules to permalinks structure.

    I’m running into this same issue when trying out 5.5.

    I am not doing any advanced redirecting, I’m basically doing something like:

    /some_page/?page=ID

    and I have code to handle the page/ID parameter on my own. When I upgraded to 5.5 it quit working and just redirects to /some_page.

    Going to have to stay with 5.4 until this gets fixed…

    Thread Starter GeraldS

    (@geralds)

    Thanks Olga, that was exactly what I needed. I managed to fix it using this in my functions.php:

    function custom_rewrite_basic() {
    	add_rewrite_tag('%course_id%', '([0-9]+)');
    	add_rewrite_rule('^course/([0-9]+)/?', 'index.php?page_id=5&course_id=$matches[1]', 'top');
      }
    add_action('init', 'custom_rewrite_basic');

    And then I could use the variable where needed with this:

    $wp_query->query_vars['course_id']

    Much cleaner than what I had before, and probably more future proof.

    Hello GeraldS,

    I have tried your solution but it doesn’t work for me so can you please explain to me that how can i overcome from this issue. I am trying to run https://localhost/builder/edit/123456 (where as builder is parent page and edit is subpage and i have assigned page template on edit page) but last segment is gone when i run this URL and i am getting https://localhost/builder/edit URL and i am not able to find last segment so can you please provide me whole code that you have implemented and it will be helpful for me if you provide me better solution.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘5.5 Update breaks custom page parameters’ is closed to new replies.