Creating a user-friendly URL can make your site easier to navigate and boost its SEO. Instead of displaying a long, unwieldy URL like example.com/files/folder/sitemap.html, you can rewrite it to a simpler version such as example.com/sitemap. This guide explains how to set up a rewrite rule in your .htaccess file using cPanel.
Step 1: Locate Your .htaccess File
Log into your cPanel account and open the File Manager. Once there, click on the Settings button in the top-right corner and enable Show Hidden Files (dotfiles). Then navigate to your public_html (or website root) directory to locate your .htaccess file. If the file does not exist, create a new one named .htaccess.
Step 2: Add Your Rewrite Rule
Edit the .htaccess file and insert the following code snippets to rewrite the long URL to a simpler version:
RewriteEngine on
RewriteRule ^sitemap/?$ /files/folder/sitemap.html [L]
This rule does the following:
- RewriteEngine on: Activates the URL rewriting engine.
- RewriteRule: Redirects any request for
/sitemap(with or without a trailing slash) to/files/folder/sitemap.html, stopping further processing with the[L]flag.
You can use the following format to create more user-friendly URLs for other pages:
RewriteRule ^your-short-url/?$ /your/long/path/to/yourfile.html [L]
Replace your-short-url with the desired friendly URL (for example, about) and /your/long/path/to/yourfile.html with the actual file path on your server.
Step 3: Save and Test Your Changes
After saving the .htaccess file, open your web browser and go to example.com/sitemap. If the rewrite rule is set up correctly, you should see the content from /files/folder/sitemap.html without the long URL appearing.
You can repeat these steps for any additional URLs you’d like to shorten by adding more RewriteRule lines in the same format.