How to Create a User-Friendly URL Using htaccess

A long, folder-heavy web address such as example.com/files/folder/sitemap.html is hard to remember, awkward to share, and rarely the address you want visitors or search engines to see. With Apache's mod_rewrite module you can serve the same page under a short, tidy address like example.com/sitemap. This guide shows you the rewrite rule to use, explains what each part does, and covers the small gotchas that trip people up.

The technique here uses a .htaccess file, the per-directory configuration file Apache reads for your site. If your site runs on Apache (the default on standard Noiz shared and reseller hosting), this is all you need.

Last reviewed: 27 July 2026, against Apache HTTP Server 2.4 (current stable) and its mod_rewrite module. This guide is written for Noiz hosting and is kept current against Apache. It complements, and does not replace, the official Apache documentation linked below.

Official Documentation Reference

Prerequisites

  • A site hosted on Apache with mod_rewrite enabled. On standard Noiz hosting this is already the case.
  • The ability to edit (or create) a .htaccess file in your site's document root, using your control panel's File Manager or an FTP client.
  • The real path to the page you want to expose under a shorter address, for example files/folder/sitemap.html.

Add the Rewrite Rule

Open the .htaccess file in your site's document root (usually the public_html or httpdocs folder). If the file does not exist yet, create a new one named exactly .htaccess, including the leading dot. Add the following, adjusting the two paths to match your own site:

RewriteEngine On
RewriteRule ^sitemap/?$ /files/folder/sitemap.html [L]

Save the file. Visitors can now reach the page at example.com/sitemap (with or without a trailing slash), while Apache quietly serves the content from the real file. The address bar keeps showing the short URL, because this is an internal rewrite rather than a visible redirect.

How the Rule Works

  • RewriteEngine On switches the rewrite engine on. It only needs to appear once at the top of the file, no matter how many rules follow.
  • ^sitemap/?$ is the pattern Apache matches against the requested path. The ^ anchors it to the start, $ to the end, and /? makes the trailing slash optional so that both /sitemap and /sitemap/ match.
  • /files/folder/sitemap.html is the real file that gets served when the pattern matches. Change this to your own target path.
  • [L] is the "last" flag. It tells Apache to stop processing further rules once this one matches, which avoids unexpected interactions with other rules in the file.

To map more pages, add one RewriteRule line per page beneath the same RewriteEngine On line, for example:

RewriteEngine On
RewriteRule ^sitemap/?$ /files/folder/sitemap.html [L]
RewriteRule ^about/?$ /pages/company/about-us.html [L]

Good to Know

  • Trailing slash. The original short snippet used ^sitemap/$, which only matched the address with a trailing slash. The /? shown above accepts both forms, which is usually what you want.
  • Internal rewrite versus redirect. The rule above rewrites the request internally, so the browser keeps showing the short URL. If you would rather send visitors to a different visible address (a genuine redirect), add the R flag, for example [R=301,L] for a permanent redirect. Only do this when you actually want the address bar to change.
  • Where the file lives. A .htaccess file applies to the folder it sits in and everything below it. Placing it in your document root covers the whole site.
  • Relative paths. If your rules live in a subdirectory and the substitution paths behave oddly, set a RewriteBase / line after RewriteEngine On to make Apache resolve paths from a known starting point.

Troubleshooting

Symptom: The site returns a 500 Internal Server Error after you save the file. This almost always means a syntax slip in the .htaccess file, or that mod_rewrite is not available. Recheck the rule for typos, make sure there is exactly one RewriteEngine On line, and confirm the file is plain text with no stray characters.

Symptom: The short URL does nothing and the long URL still works. Confirm the file is named exactly .htaccess (with the leading dot and no .txt extension), that it is in the correct document root, and that the pattern matches the address you are typing. A browser can also cache an earlier response, so test in a private window or after clearing the cache.

Symptom: The page loads but its images, stylesheets, or links break. This happens when the page uses paths relative to its original folder. Switch the page to root-relative paths (beginning with /) or absolute URLs so they resolve correctly under the new short address.

If you are on a managed Noiz plan and would prefer the rewrite set up for you, contact the Noiz support team with the long URL and the short address you want, and the team will put it in place.

  • 0 Users Found This Useful
  • htaccess, redirect, apache, url
Was this answer helpful?

Related Articles

How to Redirect a Page or Website Using .htaccess

When a page moves or a whole site changes address, a redirect sends visitors (and search engines)...

How to Create User-Friendly URLs Using .htaccess

A user-friendly URL (sometimes called a clean, pretty, or search-engine-friendly URL) is a short,...

How to Redirect a Page to Another Page or Website Using .htaccess

When a page on your website moves or is retired, sending visitors and search engines to the...

How to Block an IP Address Using .htaccess

An .htaccess file lets you block a single IP address, a range of addresses, or an entire network...