Clean your WordPress Permalinks for Better SEO

Published in: SEO - WordPress

WordPress is pretty smart at resolving URLs even if you add any number of extra parameters to the permalinks.

To give you an example, if a WordPress site is located at, all the following URLs will work fine as the various parameters found in the Query String (like the utm_source parameter added by Google Analytics) will simply get ignored by WordPress.


These parameters are often added to WordPress URLs by external services that aren’t in your control – for instance, URL shorteners or services that feed your blog to social sites.

Why Clean your WordPress URLs?

Why should you even consider cleaning up your WordPress URLs when these parameter do no harm? Well, here are a a few reasons:

#1. Technically, the URL is not the same as which is not the same as – the real canonical version. Thus if someone were to bookmark or share these URLs on social sites, it would be really hard for you to consolidate the social media metrics.

#2. The second reason is Google. If you open the HTML Suggestions section of your Google Webmaster Tools dashboard, you may come across pages that are found to duplicate title tags (and thus duplicate content). The underlying URLs are same but since they have different parameters, Google may sometimes confuse them as separate pages. You definitely want to avoid this situation.

How to Remove Extra Parameters from WordPress URLs

You cannot prevent other services from adding new parameters to your URLs but you can always redirect these URLs to the ‘clean’ versions so that there exists only one version of your URLs on the Internet.

There are two ways do that:

1. The JavaScript version: Open the header.php file of your WordPress template and copy-paste the following code somewhere inside the <head> tag.

<?php if(!is_search()) { ?>
 <script type="text/javascript">
           var url = window.location.href;
           if ( url.split('?').length >= 2 ) {
                   window.location = url.split("?")[0];
<?php } ?>

The code checks the incoming URL request for any parameters and if found, it will simply strip all the parameters from the URL and reloads the WordPress page with the clean URL.

The above approach uses JavaScript and will therefore be mostly invisible to Google. It also won’t solve any of the previously mentioned problems so let’s try something else.

2. The .htaccess version: Open the .htaccess file of your domain and copy-paste the following code above the mod_rewrite rules that were added by WordPress. You don’t have to change any code in your PHP templates.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} .
RewriteCond %{QUERY_STRING} !^(s|p)=.*
RewriteCond %{REQUEST_URI} !.\*wp-admin.*
RewriteRule ^(.*)$ /$1? [R=301,L]

If you have never used mod_rewrite before, the above might look a bit confusing but it’s actually quite simple.

It first ignores URLs that have ‘s’ or ‘p’ parameters since we don’t want to remove any of the Post IDs, like, or the search parameters like from the WordPress URLs. It also ignores request coming from the WordPress admin (wp-admin)dashboard. Finally, we do a 301 redirect thus also passing all the Google Juice to the clean and canonical URL.

There’s one important thing to note here. Any functionality that depends on URL parameters will obviously not work if you remove those parameters. That should not be a problem for most WordPress sites, but do keep that in mind before making the change.

📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: SEO - WordPress

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube