Atšķirības starp "Mod rewrite/en" versijām

No ''Hostnet Wiki''
Pārlēkt uz: navigācija, meklēt
(Jauna lapa: Mod rewrite)
 
 
(36 starpversijas, ko mainījis viens dalībnieks, nav parādītas)
2. rindiņa: 2. rindiņa:
 
<languages />
 
<languages />
  
= '''Kā veidot redirectus izmantojot .htaccess failu cpanelī ? ''' =
 
  
Mod_Rewrite – norāda kā web lapas un linki tiek uzrādīti apmaklētājiem.
+
= '''How to create redirect using the .htaccess file in cpanel? ''' =
  
Mēs vēlētos vērst jūsu uzmanību uz Mod_Rewrite noteikumu izmantošanu .htaccess failā.
+
Mod_Rewrite – specifies how web pages and URLs are displayed to the visitors.
  
Pirms novirzīšanas izveidošanas jums vajadzētu izvēlēties pārsūtīšanas veidu, kas jums būtu piemērotākais:
+
We would like to draw your attention to the usage of Mod_Rewrite rules in .htaccess file.
  
 +
Before creating a redirect, you should choose the redirection type which would be more preferable for you:
  
Pastāvīgai novirzīšanai ir statusa kods 301, un pretēji pagaidu failam, tas ir kešatmiņā pārlūka atmiņā. Tas nozīmē, ka lapa ir pārvietota un pieprasa, lai visi meklētājprogrammas un lietotāja aģenti nonāktu pie lapas, lai atjauninātu URL savā datubāzē. Tas ir visizplatītākais novirzīšanas veids.
 
  
Pagaidu novirzīšana nozīmē, ka lapa nosūta pārlūkprogrammai statusa kodu 302. Kods 302 norāda, ka pārlūkprogrammai nav jāpārklāj šī novirzīšana savos saglabātajos datos. Tas novirzīs apmeklētāju vai meklētājprogrammu, bet meklētājprogramma turpinās indeksēt sākotnējā lapā. Šis ir ieteiktais novirzīšanas veids, ja vien neesat pilnīgi pārliecināts, ka jūs nekad to nemainīsit nākotnē.
+
Permanent redirect has a status code of 301, and unlike the temporary one, it is cached in the browser memory. It implies that the page has been moved and requests all search engines and user agent coming to the page to update the URL in their database. This is the most common type of redirect.
  
Zemāk atrodamo visbiežāk lietoto un noderīgo novirzīšanas sarakstu, ko var iestatīt, izmantojot .htaccess failu ('''piemēros norādītie domēni jāaizstāj ar saviem'''):
+
Temporary redirect means that the page is sending status code 302 to the browser. Code 302 tells the browser not to cache this redirect into its saved data. It will redirect the visitor or search engine, but the search engine will continue to index to the original page. This is the recommended type of redirect, unless you are absolutely sure that you will never change it in the future.
  
 +
The list of the most common and useful redirects, which can be set through the .htaccess file, can be found below (the domains specified in the examples should be replaced with your own ones):
  
Pastāvīga novirzīšana no example.com uz domain.com
 
  
         RewriteEngine On
+
Permanent redirect from example.com to domain.com
 +
 
 +
          
 +
RewriteEngine On
 
         RewriteCond %{HTTP_HOST} ^example\.com$ [OR]  
 
         RewriteCond %{HTTP_HOST} ^example\.com$ [OR]  
 
         RewriteCond %{HTTP_HOST} ^www\.example\.com$  
 
         RewriteCond %{HTTP_HOST} ^www\.example\.com$  
26. rindiņa: 28. rindiņa:
  
  
Pagaidu novirzīšana no example.com uz domain.com
+
Temporary redirect from example.com to domain.com
  
 
         RewriteEngine On
 
         RewriteEngine On
34. rindiņa: 36. rindiņa:
  
  
PIEZĪME. Tālāk ir norādīti pastāvīgo novirzīšanas piemēri. Pagaidu var definēt, aizstājot [R = 301, L] ar [R = 302, L] koda beigās (ja nepieciešams).
+
NOTE: Below are the examples of permanent redirects. Temporary one can be defined by replacing [R=301,L] with [R=302,L] in the end of the code (where necessary).
  
  
Pāradresēt no example.com/subfolder uz domain.com
+
Redirect from example.com/subfolder to domain.com
  
 
         RewriteEngine On
 
         RewriteEngine On
45. rindiņa: 47. rindiņa:
  
  
Novirzīt no HTTP uz HTTPS
+
Redirect from HTTP to HTTPS
  
noteiktam domēnam example.com:
+
for a certain domain, example.com:      
          RewriteEngine On  
+
RewriteEngine On  
 
           RewriteCond %{HTTPS} !=on  
 
           RewriteCond %{HTTPS} !=on  
 
           RewriteRule .* https://example.com/%{REQUEST_URI} [R,L]
 
           RewriteRule .* https://example.com/%{REQUEST_URI} [R,L]
  
vai
+
 
  RewriteCond %{SERVER_PORT} 80       
+
or
 +
RewriteCond %{SERVER_PORT} 80       
 
         RewriteCond %{HTTP_HOST} ^example\.com$ [OR]  
 
         RewriteCond %{HTTP_HOST} ^example\.com$ [OR]  
 
         RewriteCond %{HTTP_HOST} ^www\.example\.com$  
 
         RewriteCond %{HTTP_HOST} ^www\.example\.com$  
59. rindiņa: 62. rindiņa:
  
  
Novirzīt no non-WWW uz WWW
+
Redirect from non-WWW to WWW
  
  
par visiem domēnu .htaccess stājas spēkā:
+
for any domain .htaccess takes effect on:
  
 
         RewriteEngine On  
 
         RewriteEngine On  
69. rindiņa: 72. rindiņa:
  
  
noteiktam domēnam example.com:
+
for a certain domain, example.com:
  
 
         RewriteEngine On     
 
         RewriteEngine On     
76. rindiņa: 79. rindiņa:
  
  
Novirzīt no WWW uz non-WWW
+
Redirect from WWW to non-WWW
  
par visiem domēnu .htaccess stājas spēkā:
+
for any domain .htaccess takes effect on:
  
 
         RewriteEngine On
 
         RewriteEngine On
85. rindiņa: 88. rindiņa:
  
  
noteiktam domēnam example.com:
+
for a certain domain, example.com:
  
 
         RewriteEngine On  
 
         RewriteEngine On  
92. rindiņa: 95. rindiņa:
  
  
Maina galvenā domēna galveno direktoriju root public_html / subfolder
+
Changes the directory root for the main domain to public_html/subfolder
  
 
         RewriteEngine on  
 
         RewriteEngine on  
104. rindiņa: 107. rindiņa:
  
  
PIEZĪME. Htaccess failam ir jāatrodas tā domēna direktorijā, kurā vēlaties konfigurēt noteikumus.
+
NOTE: The .htaccess file should be located in the directory root of the domain you wish to configure certain rules for.
  
  
  
Atspējojot esošos .htaccess noteikumus
+
Disabling existing .htaccess rules
  
  
Ja jums ir jāatspējo daži no spēkā esošajiem noteikumiem, piemēram, testēšanas nolūkos, varat tos vienkārši komentēt. Lai to izdarītu, katras noteikuma rindas sākumā pievienojiet apzīmējumu #:
+
If you need to disable some of the existing rules, for example, for testing purposes, you can simply comment them out. In order to do so, add the pound sign # at the beginning of each line of the rule.
  
  

Pašreizējā versija, 2018. gada 24. jūlijs, plkst. 10.16

Citas valodas:
English • ‎latviešu


How to create redirect using the .htaccess file in cpanel?

Mod_Rewrite – specifies how web pages and URLs are displayed to the visitors.

We would like to draw your attention to the usage of Mod_Rewrite rules in .htaccess file.

Before creating a redirect, you should choose the redirection type which would be more preferable for you:


Permanent redirect has a status code of 301, and unlike the temporary one, it is cached in the browser memory. It implies that the page has been moved and requests all search engines and user agent coming to the page to update the URL in their database. This is the most common type of redirect.

Temporary redirect means that the page is sending status code 302 to the browser. Code 302 tells the browser not to cache this redirect into its saved data. It will redirect the visitor or search engine, but the search engine will continue to index to the original page. This is the recommended type of redirect, unless you are absolutely sure that you will never change it in the future.

The list of the most common and useful redirects, which can be set through the .htaccess file, can be found below (the domains specified in the examples should be replaced with your own ones):


Permanent redirect from example.com to domain.com


RewriteEngine On

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


Temporary redirect from example.com to domain.com

        RewriteEngine On
        RewriteCond %{HTTP_HOST} ^example\.com$ [OR] 
        RewriteCond %{HTTP_HOST} ^www\.example\.com$ 
        RewriteRule ^(.*)$ "http\:\/\/domain\.com\/" [R=302,L]


NOTE: Below are the examples of permanent redirects. Temporary one can be defined by replacing [R=301,L] with [R=302,L] in the end of the code (where necessary).


Redirect from example.com/subfolder to domain.com

        RewriteEngine On
        RewriteCond %{HTTP_HOST} ^example\.com$ [OR] 
        RewriteCond %{HTTP_HOST} ^www\.example\.com$ 
        RewriteRule ^subfolder$ "http\:\/\/domain\.com\/" [R=301,L] 


Redirect from HTTP to HTTPS

for a certain domain, example.com: RewriteEngine On

         RewriteCond %{HTTPS} !=on 
         RewriteRule .* https://example.com/%{REQUEST_URI} [R,L]


or RewriteCond %{SERVER_PORT} 80

        RewriteCond %{HTTP_HOST} ^example\.com$ [OR] 
        RewriteCond %{HTTP_HOST} ^www\.example\.com$ 
        RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] 


Redirect from non-WWW to WWW


for any domain .htaccess takes effect on:

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


for a certain domain, example.com:

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


Redirect from WWW to non-WWW

for any domain .htaccess takes effect on:

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


for a certain domain, example.com:

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


Changes the directory root for the main domain to public_html/subfolder

        RewriteEngine on 
        RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
        RewriteCond %{REQUEST_URI} !^/subfolder/ 
        RewriteCond %{REQUEST_FILENAME} !-f 
        RewriteCond %{REQUEST_FILENAME} !-d 
        RewriteRule ^(.*)$ /subfolder/$1 
        RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
        RewriteRule ^(/)?$ subfolder/index.php [L] 


NOTE: The .htaccess file should be located in the directory root of the domain you wish to configure certain rules for.


Disabling existing .htaccess rules


If you need to disable some of the existing rules, for example, for testing purposes, you can simply comment them out. In order to do so, add the pound sign # at the beginning of each line of the rule.