Difference between revisions of "Mod rewrite"
From Hostek.com Wiki
(Created page with "==General Information== Mod rewrite is available on our Linux servers and can be used to rewrite or redirect your site to a particular URL. ==Redirecting to a Sub Folder== <p...") |
|||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | __FORCETOC__ | ||
+ | |||
==General Information== | ==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 [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.] | ||
− | ==Redirecting to a | + | <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 8: | Line 21: | ||
RewriteRule (.*) http://www.example.com/$1 [R=301,L] | RewriteRule (.*) http://www.example.com/$1 [R=301,L] | ||
RewriteRule ^$ testdirectory [L] | RewriteRule ^$ testdirectory [L] | ||
+ | </pre> | ||
+ | |||
+ | ===HTTP to HTTPS=== | ||
+ | <pre> | ||
+ | RewriteEngine On | ||
+ | RewriteCond %{HTTPS} off | ||
+ | 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:
- 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
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}