1

I have a WordPress page with the following structure website.com.au/pre-registration/parameter-value/, where the parameter value was originally a GET parameter, but I was requested to make it part of the URL.

How do I make my .htaccess understand that he must disregard the last part and led the user to website.com.au/pre-registration instead of returning a 404? Ideally, it will still display the whole URL, but load only website.com.au/pre-registration

Tried many possibilities I found on the web, but none worked.

My .htaccess looks like this at the moment:

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.

<IfModule mod_rewrite.c>
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET,PUT,POST,DELETE"
Header set Access-Control-Allow-Headers "Content-Type, Authorization"

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
2
  • 1
    "How do I make my .htaccess understand" - You don't. It's WordPress that you need to make understand the new URL structure. Nothing to change in .htaccess. This needs to be asked on wordpress.stackexchange.com, but you would need to remove the ".htaccess" aspect to make it on-topic.
    – MrWhite
    Commented Jun 11 at 16:20
  • 1
    “It's WordPress that you need to make understand the new URL structure” was enough to help solve the problem, thanks. Commented Jun 12 at 3:26

1 Answer 1

1

Htaccess wasn't cooperating to the solution, so went for WordPress actions as shown in this answer and added the following to functions.php:

add_action('init', 'prereg_init');
function prereg_init()
{
    // Remember to flush the rules once manually after you added this code!
    add_rewrite_rule(
        // The regex to match the incoming URL
        'pre-registration/([^/]+)/?',
        // The resulting internal URL: `index.php` because we still use WordPress
        // `pagename` because we use this WordPress page
        // `designer_slug` because we assign the first captured regex part to this variable
        'index.php?pagename=pre-registration&clubg=$matches[1]',
        // This is a rather specific URL, so we add it to the top of the list
        // Otherwise, the "catch-all" rules at the bottom (for pages and attachments) will "win"
        'top'
    );
}

Worked like a charm.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .