• I’m by no means an expert in URL rewriting, so I thought I’d ask before jumping in and playing around with this: is there a particular rewrite rule I could specify that won’t break my SEO friendly URLs?

    I realize that’s a broad question, so for example:
    https://some.site/main-page/sub-page/?parameter=value

    What I’m aiming to do is:
    https://some.site/main-page/sub-page/parameter/value

    I know in theory it can be done, but before I start dabbling to get it working I thought I’d check in to see if there was a known rule that could be used here. The last thing I want to do is to break every other page permalink trying to do so.

    Awesome plugin, by the way! It’s exactly what I’m looking for to help prevent coupon redemption abuse with WooCommerce!

Viewing 1 replies (of 1 total)
  • Thread Starter bmcconach

    (@bmcconach)

    After a bit of Googling, I discovered the add_rewrite_rule function that can be placed in my functions.php file. Using this, I was able to achieve my goal to an extent without touching .htaccess with the below code:

    function custom_rewrite_rule() {
    	add_rewrite_rule('^main-page/sub-page/([^/]*)/([^/]*)/?', 'index.php?page_id=1234&$=matches[1]&=$matches[2]','top');
    }
    add_action('init', 'custom_rewrite_rule');

    The issue I’m running into at this point is that the page will not pick up the parameter from the redirect. When loading the page with the new method, the [ifurlparam param=”value”] displays a blank page, not getting the parameter from the redirect. If I load the page using the non-SEO-friendly URL, it loads just fine.

    Any thoughts on this would be greatly appreciated!

    • This reply was modified 7 years, 1 month ago by bmcconach.
Viewing 1 replies (of 1 total)
  • The topic ‘.htaccess SEO Friendly URLs’ is closed to new replies.