• Resolved mplusplus

    (@mplusplus)


    Hi there
    On a WordPress site, what htaccess RewriteRule can rewrite URLs starting with “city-” to “/index.php?page_id=5”?
    I tried the one below, and it redirects, while I want to rewrite the URLs.
    RewriteRule ^city-.*$ /index.php?page_id=5 [L]

    Thanks.

    • This topic was modified 2 years, 4 months ago by mplusplus.
Viewing 2 replies - 1 through 2 (of 2 total)
  • In WordPress you could do this as follows:

    function custom_rewrite_rule() {
    	add_rewrite_rule('^city-([^/]*)?', 'index.php?page_id=2', 'top' );
    }
    add_action('init', 'custom_rewrite_rule', 10);

    After you have added this to your child theme or plugin, be sure to re-save the permalinks so that it works.

    Thread Starter mplusplus

    (@mplusplus)

    @threadi that worked like charm – thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘What htaccess RewriteRule can rewrite URLs to “/index.php?page_id=5”?’ is closed to new replies.