Search-engine-friendly URLs and redirects with .htaccess Print

  • .htaccess, Weiterleitung, URL
  • 0

Rules in the .htaccess file let you permanently redirect visitors to new addresses or make long URLs shorter and more search-engine friendly. How to open the file is explained in the article "Edit the .htaccess file".

Procedure

  1. Open the File Manager in cPanel and enable Show Hidden Files (dotfiles) under Settings.
  2. Edit the .htaccess file in public_html, making a copy first.
  3. Add the appropriate rule from the examples below at the top of the file and save.
  4. Test the addresses in a private browser window.

Examples

Redirect all requests to HTTPS:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]

Permanently redirect a single page (301):
Redirect 301 /old-page.html https://www.yourdomain.ch/new-page/

Short URL for a nested file: yourdomain.ch/sitemap shows the content of /files/folder/sitemap.html:
RewriteEngine On
RewriteRule ^sitemap/?$ /files/folder/sitemap.html [L]

Note: You can also set up simple redirects without code in cPanel under Domains > Redirects. In WordPress, manage permalinks under Settings > Permalinks and do not change the WordPress block in .htaccess. A 500 error after saving indicates a typo – restore your copy in that case.


Was this answer helpful?

« Back

Powered by WHMCompleteSolution