create 301 redirection using .htaccess

So far we’ve learned that .htaccess can easily be used to make some tweaks over Apache Web Server’s configuration. Now we’re going to learn that how can we create SEO Friendly URL using .htaccess.

How to create SEO Friendly URL using .htaccess

STEP 1: Login to your cPanel Account. Navigate to File Manage under Files section. Browse to public_html folder & open .htaccess on editor.

STEP 2: Let’s think you’ve got a dynamic URL like https://www.yourwebsite.com/products.php?keyval=25&keyval2=65 which you need to convert to a SEO Friendly URL. Well, write the codes below in your .htaccess file to perform this task

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} "keyval\=25&keyval2\=65$ [NC]
RewriteRule ^products.php$ https://www.yourwebsite.com/household-products.php? [r=301]

Note: Don’t forget to put a (?) question mark at the end of the substitution URL you’ve created. Otherwise query string will be appended at the end of the substitution URL.

  • Was this article Helpful ?
  • yes   no

Leave a Reply