• I’m working on a marketing website. My requirement is that except for a few pages, every request like https://hirisemarketing.com/<anything&gt; will redirect to a page (which I’ve already created through wp admin) https://hirisemarketing.com/marketing. This page has a shortcode which lets me create a full-fledged dynamic code through a plugin.

    Everything is good except i am unable to do the redirection. I have created rewrite rules for some of the pages as per my needs like this:

    add_rewrite_rule('ads/([^/]+)?$', 'index.php?pagename=ads&adct=$matches[1]', 'top');
    add_rewrite_rule('renew/([^/]+)?$', 'index.php?pagename=renew&arcd=$matches[1]', 'top');
    add_rewrite_rule('image-gallery/([^/]+)?$', 'index.php?pagename=image-gallery&adpid=$matches[1]', 'top');

    They are all working fine. But here I want to create the redirection as i mentioned above. I’ve tried many possibilities like:

    add_rewrite_rule('([^/]+)?$', 'index.php?pagename=marketing&bizpermalink=$matches[1]', 'top');

    but no luck. Please help!

    Thanks,
    baburman

Viewing 2 replies - 1 through 2 (of 2 total)
  • If you would like to change the Page not found page into a redirect document to go to the page you’ve already created, do this.

    instead of a Page not found error, I want it to say: This page is under construction. find the document for page not found (in your ftp), and replace it with a file like this

    <meta http-equiv="refresh" content="0; URL='https://domain.com/ex'" />

    hopefully this helped!

    Moderator bcworkz

    (@bcworkz)

    Not a bad idea making use of the 404 feature. Its success depends on whether you want to redirect requests to other existing pages or not. To redirect requests to other valid pages you do need a rewrite rule.

    This regexp: '^([^/]+)?/?$'
    should capture any single parameter URL, but not any multiple parameter ones. You were soooo close! This will capture example.com/foobar/ but not example.com/foobar/snafu/. This will effectively prevent requesting other existing posts and pages by their simple permalink. One could still get to them by inserting an appropriate parameter in front, such as the published year, as in: example.com/2016/foobar/

    You might consider giving your other regexps the same treatment. Begin each with a caret ^ so the request must begin with one of your initial terms and not if they occur farther down, as in example.com/foobar/ads/snafu/ which will lead to the ads page without the caret but not with. It’s up to you if you want to make this distinction or not.

    You definitely should include /? in front of terminal $ in all cases, as this covers URLs that may or may not have a terminal slash /. As your regexps are now, an URL like example.com/ads/foobar will be captured but not example.com/ads/foobar/. Adding the /? captures either one.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to redirect every request to a single page.’ is closed to new replies.