Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9240779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:14:56+00:00 2026-06-18T08:14:56+00:00

I’ve added a query string to my WordPress installation using the following code in

  • 0

I’ve added a query string to my WordPress installation using the following code in my functions.php file:

function add_query_vars($aVars) {
    $aVars[] = "username";
    return $aVars;
}

add_filter('query_vars', 'add_query_vars');

function add_rewrite_rules($aRules) {
    $aNewRules = array(
        '([^/]+)/manage' => 'index.php?pagename=manage&username=$matches[1]',
        '([^/]+)/settings' => 'index.php?pagename=settings&username=$matches[1]',
    );
    $aRules = $aNewRules + $aRules;
    return $aRules;
}

add_filter('rewrite_rules_array', 'add_rewrite_rules');

However, I don’t want to load the page template if the username query string is empty, rather I’d like to redirect to the homepage. For instance:

website.com/myusername/manage

… would load a page template

website.com/manage

… would redirect home.

Can I do this using WordPress’ rewrite engine or should I take another approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:14:57+00:00Added an answer on June 18, 2026 at 8:14 am

    Well, I would use this code:

    function redirect_to_homepage( $query ) {   
        //page manage and settings does NOT exits
        if ( $query->is_main_query() && ( $query->query_vars['name'] == 'manage' || $query->query_vars['name'] == 'settings' ) ){       
            if( ( !array_key_exists( 'username', $query->query_vars ) || ( array_key_exists( 'username', $query->query_vars ) && trim($query->query_vars['username']) == '' ) ) ) {
                wp_redirect( get_bloginfo('url') );
                exit;
            }   
        }
        //page manage and settings does exits
        if ( $query->is_main_query() && ( $query->is_page('manage') || $query->is_page('settings') ) ){
            if( ( !array_key_exists( 'username', $query->query_vars ) || ( array_key_exists( 'username', $query->query_vars ) && trim($query->query_vars['username']) == '' ) ) ) {
                wp_redirect( get_bloginfo('url') );
                exit;
            }   
        }
    }
    add_action( 'parse_query', 'redirect_to_homepage' );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want to count how many characters a certain string has in PHP, but
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I would like to count the length of a string with PHP. The string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.