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

No ''Hostnet Wiki''
Pārlēkt uz: navigācija, meklēt
(Jauna lapa: Before creating a redirect, you should choose the redirection type which would be more preferable for you:)
(Jauna lapa: 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...)
12. rindiņa: 12. rindiņa:
  
  
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.
+
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.
  
 
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ē.
 
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ē.

Versija, kas saglabāta 2018. gada 24. jūlijs, plkst. 10.09

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.

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ē.

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):


Pastāvīga novirzīšana no example.com uz domain.com

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


Pagaidu novirzīšana no example.com uz domain.com

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


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).


Pāradresēt no example.com/subfolder uz domain.com

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


Novirzīt no HTTP uz HTTPS

noteiktam domēnam example.com:

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

vai

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


Novirzīt no non-WWW uz WWW


par visiem domēnu .htaccess stājas spēkā:

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


noteiktam domēnam example.com:

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


Novirzīt no WWW uz non-WWW

par visiem domēnu .htaccess stājas spēkā:

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


noteiktam domēnam example.com:

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


Maina galvenā domēna galveno direktoriju root 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] 


PIEZĪME. Htaccess failam ir jāatrodas tā domēna direktorijā, kurā vēlaties konfigurēt noteikumus.


Atspējojot esošos .htaccess noteikumus


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 #: