add_rewrite_rule won’t work

I did it in the past and it did work. But this time it won’t work and I can’t figure out why. The difference is the version of WordPress and the version of WPML.

So, I have the latest version of both:

WP : Version 4.7.3
WPML : Version 3.6.3

My .htaccess is:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

And my function PHP contain this code:

function custom_rewrite_rule()
{
    add_rewrite_rule('^nos-ecoles/ecole/(.+?)/?', 'index.php?page_id=153&school=$matches[1]&lang=fr', 'top');
    add_rewrite_rule('^our-schools/school/(.+?)/?', 'index.php?page_id=151&school=$matches[1]&lang=en', 'top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);

function custom_rewrite_tag() {
    add_rewrite_tag('%school%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);

Note that the page ID in both case are good. English and French are OK, I did validate it.

Problem is when I access the page like the following exemple (chinatown is the school param), it remove the param and keep the page only:
http://shaolinwingchun.mahlea.ca/fr/nos-ecoles/ecole/chinatown/

But when I try to access the page like the following exemple, it works and the param stay in place:
http://shaolinwingchun.mahlea.ca/fr/nos-ecoles/ecole/?school=chinatown

Note that each time I change my function.php, I save my Permalink Settings to reset it.

Any idea how to make it works?????

0

Leave a Comment