Difference between revisions of "Mod rewrite"

From Hostek.com Wiki
Jump to: navigation, search
 
Line 1: Line 1:
 +
__FORCETOC__
 +
 
==General Information==
 
==General Information==
Mod rewrite is available on our Linux servers and can be used to rewrite or redirect your site to a particular URL.
+
Mod_Rewrite is available on our Linux/cPanel servers and can be used to rewrite or redirect your site to a particular URL.
  
==Redirecting to a Sub Folder==
+
*The Apache Module "Mod_Rewrite" is also enabled on our LiteSpeed servers, and is very similar to "ISAPI_Rewrite", which is the (Windows) IIS Module alternative.
 +
*For more information on Mod_Rewrite please see our [https://wiki.hostek.com/URL_Rewrite#Apache_.28Linux.29 URL Rewrite Wiki.]
 +
*For more information on ISAPI_Rewrite please see our [https://wiki.hostek.com/ISAPI_Rewrite ISAPI Rewrite Wiki.]
 +
 
 +
<pre>
 +
IMPORTANT: Place the rewrite rules in a file named .htaccess and place it in the website's Default Directory(i.e. the \wwwroot folder).
 +
</pre>
 +
*If you do not have an .htaccess file already created you can:
 +
*#Open a text editor--like Notepad--and save the file as ".htaccess".
 +
*#Use the File Manager in the hosting control panel to create a .htaccess file on the server.
 +
 
 +
===Redirecting to a Subfolder===
 
<pre>
 
<pre>
 
RewriteEngine on
 
RewriteEngine on
Line 10: Line 23:
 
</pre>
 
</pre>
  
==HTTP to HTTPS==
+
===HTTP to HTTPS===
 
<pre>
 
<pre>
 
RewriteEngine On
 
RewriteEngine On
Line 16: Line 29:
 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
 
</pre>
 
</pre>
 +
 
[[Category:Linux]]
 
[[Category:Linux]]

Latest revision as of 22:13, 18 January 2017


General Information

Mod_Rewrite is available on our Linux/cPanel servers and can be used to rewrite or redirect your site to a particular URL.

  • The Apache Module "Mod_Rewrite" is also enabled on our LiteSpeed servers, and is very similar to "ISAPI_Rewrite", which is the (Windows) IIS Module alternative.
  • For more information on Mod_Rewrite please see our URL Rewrite Wiki.
  • For more information on ISAPI_Rewrite please see our ISAPI Rewrite Wiki.
IMPORTANT: Place the rewrite rules in a file named .htaccess and place it in the website's Default Directory(i.e. the \wwwroot folder).
  • If you do not have an .htaccess file already created you can:
    1. Open a text editor--like Notepad--and save the file as ".htaccess".
    2. Use the File Manager in the hosting control panel to create a .htaccess file on the server.

Redirecting to a Subfolder

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ testdirectory [L]

HTTP to HTTPS

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}