Rewrite url without special characters

#791425
  • Michele
    Rank Math free

    Hi, I would still like to ask for your precious help.I would like to remove any special characters (other than letters and numbers, therefore) in the part of the link after the /ita/ folder.

    You already helped me with regex rules and writing the rule on htaccess for another problem. Can you help me now too?

    Thanks a lot

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    I appreciate you reaching out for assistance. To remove any special characters (excluding letters and numbers) from the part of the link after the /ita/ folder, you can utilize a regex redirection in Rank Math.

    Here is the regex code you can use:

    /ita/([a-zA-Z0-9]+)

    In this regex code:

    • /ita/ specifies the folder path.
    • ([a-zA-Z0-9]+) captures any combination of letters and numbers after the /ita/ folder.

    You can add this regex code to the Source URLs field in Rank Math’s Redirection feature. Ensure to select the Regex matching type and set the Destination URL as per your requirements.

    If you encounter any issues or need further assistance, feel free to let us know. We are here to help!

    Thank you for bringing up this concern.

    Sources:
    How to Redirect to URLs With Trailing Slash » Rank Math
    How to Remove a Specific Word From Your Permalinks (URLs) » Rank Math
    Solving Redirection Issues Using Rank Math SEO Plugin » Rank Math
    How to Edit Your htaccess File Using Rank Math » Rank Math

    This is an automated reply from Rank Math Support Bot. Your ticket has been assigned to a human agent and we will get back to you shortly.

    Michele
    Rank Math free

    It’s not clear to me what I should do

    Hello,

    Unfortunately, Rank Math does not have any feature to update your URLs to remove the hyphen per words.

    However, you may try to use and customize this filter to achieve that on your site:

    function no_dashes( $slug, $post_ID, $post_status, $post_type ) {
    
        if( $post_type == "post" ) {
            $slug = str_replace( '-', '', $slug);
        }
        return $slug;
    }
    add_filter( "wp_unique_post_slug", "no_dashes", 10, 4 );

    Here’s a guide to adding the code to the website:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Please note that it will work only when you save a post. For new posts, it will work just fine. But for existing posts, you have to go and edit/hit update/save to make it happen. You can remove the condition to apply it to your whole site.

    Hope that helps.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this ticket.