Notes on Creating Rewrite Rules
Please Note:
The text on this page was translated by translation software. A revised version from our editors will be available soon.
Please use the “Print” function at the bottom of the page to create a PDF.
For Linux Web Hosting packages and Managed Dedicated Servers
Learn what to look for if your rewrite rules are not working as intended.
You can rename and redirect pages in an .htaccess file using rewrite rules. For example, rename the URLs of your web pages for search engine optimization (SEO) or redirect your visitors to your SSL secured site.
About the .htaccess File
Rewrite rules are defined in an .htaccess file on the server. We suggest you review how to Create Files with a Dot Prefix on Windows PCs. It is important that the file uploaded via Webspace Explorer or FTP is named .htaccess.
Enable the RewriteEngine Module (mod_rewrite)
The Apache module mod_rewrite is already available for Web Hosting packages. You have to enable the module by adding the following line to the beginning of your .htaccess file:
RewriteEngine On
RewriteBase Parameter and Directory Specification
After enabled the RewriteEngine, the RewriteBase must be defined next in the .htaccess file:
RewriteBase /
RewriteBase defines what should be added to the end of your domain before applying the rewrite rules. If RewriteBase /folder/ was used, then every rewrite would be started with http://www.example.com/folder/ (where 'example.com' is used in place of your domain name). Then the rewrite rules are applied, which will output the rest of the URL path.
Rewriterule That Keeps the Same Path
If you want the RewriteRule to leave the path after the domain intact, but redirect to a different page, do not specify any forward slash or directory path in your RewriteRule.
# Turns http://example.com/about-us/contact-us.html into http://example.com/about-us/contact.php
RewriteEngine On
RewriteBase /
RewriteRule contact-us.html contact.php
RewriteRule That Specifies the Full Path
If you want to specify the full path of the redirect, add the full path to the RewriteRule:
# Turns http://example.com/blogpost.php into http://example.com/blog/posts/blogpost.php
RewriteEngine on
RewriteBase /
RewriteRule blogpost.php /blog/posts/blogpost.php
Tips for Avoiding Errors
Please note: Rewrite rules can be very complex and can cause an error of 500 even with the smallest uncleanliness. Such errors can result from the fact that only one character was entered incorrectly. This is not a server failure. As a rule, the website will function without problems as soon as the corresponding lines in the.htaccess have been commented out.
Here we list the most common causes of errors that can ensure that a rewrite rule does not take effect, even if it does not produce an error 500.
Make sure that the.htaccess has been placed in the correct directory. Note that an.htaccess is recursive. It therefore affects the directory in which it was saved and its respective subdirectories.
Avoid multiple nested.htaccess files on a path level. Errors in a subdirectory's.htaccess can under certain circumstances also negatively affect higher-level rewrite rules at upper directory levels.
For this reason, it is best to create a separate directory for each domain or web presence. This allows you to conveniently define separate.htaccess files and rewrite rules for each domain that do not interfere with each other.
Have you created a protected directory in the same directory using IONOS? This function overwrites self-created.htaccess files and thus makes your rewrite rules ineffective. Our recommendation: Create the directory protection yourself in your.htaccess using the help article Set up directory protection using.htaccess and FTP.
Check whether functions are commented out (disabled). Some pre-built scripts and content management systems (CMS), such as Joomla, comment out rewrite rules to avoid problems during installation. In a.htaccess, commands are commented out by prefixing a line with a hash (#):
# Turns http://example.com/blog.html into http://example.com/index.php?page=blog
RewriteEngine on
RewriteBase /
RewriteRule ^([a-z]+)\.html$ /index.php?page=$1 [R,L]
In this example, the actual RewriteRule was commented out and therefore does not apply. Remove the hash before RewriteRule and save the modified.htaccess on the server.
- Check whether the required file permissions (chmod) have been assigned to the.htaccess. In the Webspace Explorer adjust the file rights by right-clicking on the.htaccess and selecting the Change rights item. Enter the value 644 in the Octal notation field. This is sufficient for the functions of a.htaccess.
- Carefully check the commands for typos and make sure nothing is missing.