Warning
The examples in the following links are provided as a courtesy. Clouding.io will not configure rewrite rules for its customers' individual websites.
General instructions
- Create a plain text file named .htaccess, or add the lines of code from the example that best suits your needs at the top of your .htaccess file(s).
- Add the lines from the example appropriate for your needs to the .htaccess file. Keep in mind that you will need to replace the text in the examples with your own information. That is, replace dominio.com with your own domain name, directorio1 with your own directory name, archivo.html with your own file name, etc.
- Use your FTP client to upload the .htaccess file to the directory, or subdirectory, of the corresponding domain. If you want the file to load when accessing your domain , for example, dominio.com, you should upload the file to your domain's root directory, which is usually:
- /var/www/vhosts/dominio.com/httpdocs – For a server with Plesk
- dominio.com/httpdocs – For shared hosting
Once you have uploaded the file, the rewrite rule should work immediately.
Warning
Some Content Management Systems (CMS), such as WordPress, for example, overwrite .htaccess files with their own configuration. In that case, you may need to find a way to make these changes from the CMS's own panel.
Example .htaccess file
The following example .htaccess file will redirect http://dominio.com/ to https://dominio.com/. It will also work if an individual file is requested, such as http://dominio.com/archivo.html:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.dominio.com/$1 [R,L]
Testing the examples
Simply visit http://dominio.com in your browser, and you should see the same page displayed, but the address has changed to https://www.dominio.com.
Also, any URL of this type will be converted: http://dominio.com/archivo.html to https://dominio.com/archivo.html.
Code explanation
- Options +FollowSymLinks – is an Apache directive, a prerequisite for mod_rewrite.
- RewriteEngine On – enables mod_rewrite.
- RewriteCond %{SERVER_PORT} 80 – indicates that you want all requests made to port 80 (Apache's default port for web service) to go through the specified rule.
-
RewriteRule – defines a particular rule.
- Within the rewrite rule, the first character string after RewriteRule defines what the original URL looks like.
- The second string after RewriteRule defines the new URL.
-
$1 – This special character replaces (or indicates) the part in parentheses specified in the first string. Basically, it ensures that subpages redirect to the same subpage and not to the home page. You can omit it to redirect to the home page. (If you do not have the same content in the new directory as in the old directory, leave this regular expression.)
Additional information
You can find more details about special characters, known as regular expressions, in the article
[R,L] – This option performs a redirect and also prevents rewrite rules written afterward from affecting the URL (a good idea to add after the last rewrite rule).