Wordpress - How to Enable SEO Friendly URL's
In Wordpress, you will need to add rewrite instruction to the function.php file.
- Log in to the WordPress Admin interface
- In the left sidebar, hover over Appearances, then click Theme Editor In the right sidebar, click functions.php
- Add the following Code to function.php after include statements as per instruction in the code.
<code data-v-37477c6a="" id="script_tag">/* add to function.php under */ /* Location: apperance->themes->theme editor */ /* Change [website-page-slug-url] to your page slug url*/ /* change page id value 1234 to your page_id, will be visible on inspect element or page source code */ function custom_rewrite_rule() { add_rewrite_rule('^[website-page-slug-url]/([^/]*)/?','index.php?page_id=11234&state1=$matches[1]','top'); add_rewrite_rule('^[website-page-slug-url]/([^/]*)/([^/]*)/?','index.php?page_id=1234&state1=$matches[1]&state2=$matches[2]','top'); add_rewrite_rule('^[website-page-slug-url]/([^/]*)/([^/]*)/([^/]*)/?','index.php?page_id=1234&state1=$matches[1]&state2=$matches[2]&state2=$matches[3]','top'); } add_action('init', 'custom_rewrite_rule', 10, 0); /* code ends here */
- Save/Update Permalink Settings
WordPress permalink settings can be found in the main settings menu of the WordPress admin area (i.e. https://www.yourwebsite.com/wp-admin/options-permalink.php).
Select 'Post name'
Save Changes. (Note: save setting even if 'Post name' is already selected.)
- Clear Cache on 'WP Engine'
Click on the 'WP Engine' menu item in the admin bar and then under ‘General’ settings click on purge all caches button.
Note: This cache clearing approach will only work for sites that are built using 'WP Engine' or you can use any WordPress trustworthy plugin to clear the cache.
- Your store locator should now feature SEO friendly URL's when visiting store pages.
----------
TROUBLESHOOTING
The general rule is to map everything after slash on the store page to the store page itself, i.e.: www.mywebsite.com/store-locator/anything → www.mywebsite.com/store-locator
Specific configuration depends on your server:
- In Apache, you will need to enable mod_rewrite and specify rewrite urls in .htaccess file See
https://httpd.apache.org/docs/2.4/rewrite/remapping.html - In Nginx, you will need to add rewrite instruction to the config file. See
https://www.nginx.com/blog/creating-nginx-rewrite-rules/
If you need additional help, please contact us for assistance.