Add Trailing Slash to the End of the URL with .htaccess Rewrite Rules Pridėti ukośnika su End of the URL. Htaccess perrašymas Taisyklės

For a website that has URLs that end with a slash (/), it's a good practice to ensure that all url links been parsed by the web server ended with trailing slash, even if visitors forget to enter the ending slash. Dėl tinklalapyje yra URL, kad pabaigoje su įstrižas brūkšnys (/), tai yra gera praktika, siekiant užtikrinti, kad visi URL nuorodos buvo apdoroti pagal žiniatinklio serverio baigėsi ukośnika, net jei lankytojai pamiršti įveskite baigiasi ukośnikiem. This avoid visitors been served with 404 Page Not Found or Page Cannot be Displayed error as some web servers treat links without trailing slash as a file name instead of directory, and thus unable to locate the documents. Tai išvengti lankytojai buvo įteiktas 404 Puslapis nerastas arba negali būti parodytas klaidos, nes kai kurie interneto serveriai gydyti nuorodos be ukośnika kaip failo vardo vietoj katalogo, ir todėl negali rasti dokumentus. It also eliminates the possibility that both pages with same content, one with slash at the end and another without, been viewed by search engines as duplicate content. Ji taip pat pašalina galimybę, kad tiek puslapių su tuo pačiu turiniu, viena iš ukośnikiem pabaigoje ir kitą, buvo peržiūrėta per paieškos sistemas kaip išrašus.

As an example, all hits to http://www.mydigitallife.info/contact should be redirect to http://www.mydigitallife.info/contact/. Pavyzdžiui, visi hitai į http://www.mydigitallife.info/contact turėtų būti nukreipti į http://www.mydigitallife.info/contact/.

Most web server, including the popular Apache HTTPD web server supports mod_rewrite module where rules can be set in .htaccess file in order to redirect to add trailing slash to the URLs that does not already have one. Dauguma žiniatinklio serverių, taip pat populiarių Apache HTTPD interneto serveris palaiko mod_rewrite modulio, jei tokios taisyklės gali būti nustatytos. Htaccess failas siekiant nukreipti pridėti ukośnika į URL, kad nėra jau turite vieną.

The following code can be put in .htaccess to redirect URL without trailing slash to URL with trailing slash: Šį kodą galima įgyvendinti. Htaccess nukreipti URL be ukośnika į URL ukośnika:

RewriteEngine On RewriteEngine On
RewriteBase / RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond% (REQUEST_FILENAME)!-F
RewriteCond %{REQUEST_URI} !index.php RewriteCond% (REQUEST_URI)! Index.php
RewriteCond %{REQUEST_URI} !(.*)/$ RewriteCond% (REQUEST_URI) !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301] RewriteRule ^(.*)$ http://domain.com/ $ 1 [L, R = 301]

or arba

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond% (REQUEST_FILENAME)!-F
RewriteCond %{REQUEST_URI} !\..+$ RewriteCond% (REQUEST_URI)! \ .. + $
RewriteCond %{REQUEST_URI} !/$ RewriteCond% (REQUEST_URI)! / $
RewriteRule (.*) http://www.mydigitallife.info/$1/ [R=301,L] RewriteRule (.*) http://www.mydigitallife.info/ $ 1 / [R = 301, L]

or arba

RewriteEngine On RewriteEngine On
RewriteBase / RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)/$ /$1 [L] RewriteRule ^ ([a-zA-z0-9 ]+)/$ / $ 1 [L]
RewriteCond %{THE_REQUEST} ^[AZ]{3,9}\ /([a-zA-Z0-9]+) RewriteCond% (THE_REQUEST) ^ [AZ] (3,9) \ / ([a-zA-z0-9] +)
RewriteRule ^([a-zA-Z0-9]+)$ /%1/? RewriteRule ^ ([a-zA-z0-9] +) $ / 1% /? [R=301,L] [R = 301, L]

In you're using CMS or blog such as Wordpress that allows custom URL structure for permalinks, especially for search engine optimization (SEO), the above code should come before the block of rewrite conditions and rules for URL customization for the CMS or blog platform. Į naudojate CMS ar interneto dienoraštį, tokių kaip WordPress, kuris leidžia vartotojo URL struktūrą nuolatinės, ypač paieškos sistemų optimizavimas (SEO), pirmiau kodas turėtų ateiti iki bloko perrašyti sąlygas ir taisykles URL pritaikyti prie PPSS ar dienoraščio platforma .

Brief explaination of the rewrite code to add trailing slash to URL Trumpas explaination iš perrašyti kodas pridėti ukośnika į URL

RewriteEngine On - This line enables the runtime rewriting engine based on mod_rewrite module of Apache. RewriteEngine On - Ši eilutė leidžia runtime redakcija variklio remiantis mod_rewrite modulio Apache.

RewriteBase / - This line sets the current page root directory as base URL for per-directory rewrites. RewriteBase / - Ši eilutė nurodo esamą puslapį namų katalogą bazės URL už katalogas perrašo.

RewriteCond %{REQUEST_FILENAME} !-f - This line excludes all URLs pointing to existed files from been added with trailing slash again. RewriteCond% (REQUEST_FILENAME)!-F - Ši eilutė neapima visos URL, nurodantis į egzistavo failų buvo pridėta ukośnika vėl. Directories cannot be excluded as this would exclude the rewrite behavior for existing directories. Katalogai atmesti negalima, nes tai paneigtų perrašyti elgesio esamų katalogų.

RewriteCond %{REQUEST_URI} !index.php - This line is optional, and will excludes a sample URL (in this case, index.php) that users do not want it to be rewritten. RewriteCond% (REQUEST_URI)! Index.php - Ši eilutė yra neprivalomas, ir neapima pavyzdys URL (šiuo atveju, index.php), kad vartotojai nenori jį perrašyti. Remove this line if not necessary. Pašalinti šią eilutę, jei nėra būtina.

RewriteCond %{REQUEST_URI} !\..+$ - Specify that the URL does not contain any . RewriteCond% (REQUEST_URI)! \ .. + $ - Nurodykite, kad adresas nėra jokių. (dot) to exclude reference to file. (dot) išbraukti nuorodą į failą.

RewriteCond %{REQUEST_URI} !(.*)/$ - This line determines which URL doesn't contain a trailing slash RewriteCond% (REQUEST_URI) !(.*)/$ - Ši eilutė nustato, kokios URL neturi būti ukośnika

RewriteRule ^(.*)$ http://www.domain.com/$1/ [L,R=301] - This line process URL without trailing slash that has passed conditions set above, by appending a trailing slash and then redirect with 301 or permanent redirect status to the new URL. RewriteRule ^(.*)$ http://www.domain.com/ $ 1 [L, R = 301] - Ši eilutė proceso URL be ukośnika kad praėjo nustatytas sąlygas aukščiau, pridėtos per ukośnika tada nukreipti su 301 arba nuolatinės peradresavimo statusą į naują adresą. L mean this is the last line to process and the rewrite process can be terminated. L reiškia tai paskutinę eilutę procesą ir perrašyti procesas gali būti nutrauktas. Remember to replace the www.domain.com with your own domain name. Nepamirškite pakeisti www.domain.com savo domeno pavadinimą.

Brief explaination for second set of rewrite rules and rule conditions Trumpas explaination dėl antrojo rinkinio perrašyti taisykles ir taisyklės sąlygos

RewriteRule ^([a-zA-Z0-9]+)/$ /$1 [L] - This line terminates the trailing slash appending rewrite process if the URL already contains trailing slash. RewriteRule ^ ([a-zA-z0-9 ]+)/$ / $ 1 [L] - Ši eilutė nutraukia ukośnika pridėtos perrašyti, jei URL jau yra ukośnika.

RewriteCond %{THE_REQUEST} ^[AZ]{3,9}\ /([a-zA-Z0-9]+) - This line determines request that does not ends with trailing slash. RewriteCond% (THE_REQUEST) ^ [AZ] (3,9) \ / ([a-zA-z0-9] +) - Ši eilutė nustato prašyti, kad nėra baigiasi ukośnika.

RewriteRule ^([a-zA-Z0-9]+)$ /%1/? RewriteRule ^ ([a-zA-z0-9] +) $ / 1% /? [R=301,L] - This line append a slash to the end of URI and perform a 301 permanent redirect to the new URL with trailing slash, and terminate the rewrite block. [R = 301, L] - Ši eilutė prideda ukośnikiem iki URI ir atlikti 301 nuolatinių nukreipti į naują URL ukośnika ir nutraukti perrašyti blokas.

IMPORTANT : The page is machine translated and provided "as is" without warranty. DĖMESIO: Šis puslapis yra mašina išvertė ir pateikiama "kaip yra" be garantijų. Machine translation may be difficult to understand. Mašininio vertimo, gali būti sunku suprasti. Please refer to Remkitės original English article originalas anglų straipsnis whenever possible. jei įmanoma.


5 Responses to “Add Trailing Slash to the End of the URL with .htaccess Rewrite Rules” 5 Responses to "Pridėti ukośnika su End of the URL. Htaccess perrašymas taisyklės"

  1. an office equipment seller biuro įrangos pardavėjas
    January 19th, 2009 19:50 Sausis 19th, 2009 19:50
    5 5

    I'd been using that slash alot on one of my website. Aš naudoju kad ukośnikiem daug vienas iš mano draugų svetainėse. Most of them had been indexed by search engine successfully, but four of them return a 404 not found error based on Google Webmaster report, weird. Dauguma jų buvo indeksuojami paieškos sėkmingai, o keturios iš jų grąžinti 404 nerastas klaidos remiantis Google webmasters pranešimą, keista.

  2. Nate Nate
    December 12th, 2008 12:53 Gruodis 12, 2008 12:53
    4 4

    I have tried both methods and they do work but not with the other statement that I have. Aš bandė abu metodus ir jos darbą, bet ne su kitais, kad aš turiu. I was wondering exactly what Killswitch meant when he says “play with it a bit.” I tried rearranging the order and that doesn't seem to help, I'm looking for a quick solution here. Zastanawiałem ką Killswitch reiškė, kai jis sako "žaisti su juo šiek tiek." Aš bandė pertvarkyti tvarka ir, kad neatrodo, kad padėtų, I'm looking for a quick tirpalo čia.

  3. Killswitch Killswitch
    December 6th, 2008 10:37 6 gruodis 2008 10:37
    3 3

    This was extremely helpful, I have been trying for the longest time to figure out how to end a site.com/somthing to site.com/something/ with no luck. Tai buvo labai naudinga, aš bandė už ilgiausiai laiko suprasti, kaip baigti site.com / somthing į site.com / kažkas / be laimingos. Had to play with it a bit due to the rules I already have, but had it working in about 5 mins. Turėjo žaisti su juo šiek tiek dėl to, kad taisyklės, aš jau turiu, tačiau jis dirba apie 5 min.

  4. com Ru
    October 31st, 2008 03:07 October 31st, 2008 03:07
    2 2

    dlvrq rjdkq bfuwo jnlx dlvrq rjdkq bfuwo jnlx

  5. Na SEO muÅ¡ke - Vybrali.sme.sk a ukonÄ ujúce lomeno v URL | SEO chat Na SEO Muà ¡ke - Vybrali.sme.sk a ukonÄ ujà ° ce lomeno prieš URL | SEO čate
    July 26th, 2008 05:19 26 liepa 2008 05:19
    1 1

    [...] Ä Ãm predÃdete aj problému Ä .2. [...] Ä am predÃdete aj problà © mu Ä .2. Pre htaccess som naÅ¡iel pekný, ale anglický Ä lánok o tom, how to add trailing slash to the end of the URL. Išankstinis Htaccess som Naa ¡IEL peknà ½, bet Anglická ½ Ä Lã ¡nok o tom, kaip pridėti ukośnika iki URL. Možnosti máte [...] MOA ¾ nosti Mà ¡te [...]

Leave a Reply Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> Galite naudoti šias žymeles: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime = ""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. Subscribe to comments funkcija buvo išjungta. To receive notification of latest comments posted, subscribe to Norėdami gauti pranešimus apie naujausius komentarų, užsiprenumeruoti My Digital Life Comments RSS feed Mano skaitmeninis gyvenimas Komentarų RSS or arba register to receive registruotis, norint gauti new comments in daily email digest. Nauji komentarai kasdien elektroniniu paštu.
Custom Search

New Articles Nauji straipsniai

Incoming Search Terms for the Article Pradedantys Paieška Sąlygos straipsnį

php htaccess trailing slash 404 Php Htaccess ukośnika 404 - -- rewrite append slash perrašyti pridėti ukośnikiem - -- wordpress trailing slash WordPress ukośnika - -- add trailing slash any directory apache pridėti ukośnika katalogą apache - -- mod_rewrite add slashes mod_rewrite pridėkite nerijos ribos - -- rewrite add trailing slash perrašyti pridėti ukośnika - -- .htaccess slash end . Htaccess ukośnikiem pabaigos - -- add trailing slash htaccess pridėti ukośnika Htaccess - -- htaccess redirect condition with slash Htaccess peradresavimo sąlyga ukośnikiem - -- htaccess base url Htaccess Pagrindinis url - -- htaccess with or without slash Htaccess su arba be ukośnikiem - -- htaccess accept links ending in a slash Htaccess priimti ryšius baigiasi ukośnikiem - -- redirect 301 mod rewrite append peradresavimai 301 mod rewrite append - -- rewriterule base directory RewriteRule bazinė katalogas - -- rewriterule trailing slash RewriteRule ukośnika - -- rewriterule trailing RewriteRule užsisklęs - -- rewriterule examples conditions RewriteRule pavyzdžiai sąlygos - -- trailing slash redirect htaccess ukośnika peradresavimai Htaccess - -- url ending or not with slash Url baigiasi arba ne įstrižas brūkšnys - -- url rewrite add slash in rule+tukey url perrašyti pridėti ukośnikiem taisyklėse + Tukey - -- websites url slash svetaines url ukośnikiem - -- what is a trailing slash kas yra ukośnika - -- .htaccess redirect trailing slash . Htaccess nukreipti ukośnika - -- htaccess slash anhängen Htaccess ukośnikiem anhängen - -- htaccess rewrite folder Htaccess perrašyti kataloge - -- htaccess add trailing slash Htaccess pridėti ukośnika - -- mod_rewrite django add_slash mod_rewrite django add_slash - -- mod rewrite trailing slash mod rewrite ukośnika - -- RewriteRule removing last trailing slash RewriteRule pašalinti paskutiniais ukośnika - -- rewrite url using slash perrašyti URL naudojant ukośnikiem - -- url rewrite+adding trailing slash url perrašyti + pridėti ukośnika - -- adding block url to htaccess pridėti bloko URL Htaccess - -- apache append slash end of filename apache pridėti ukośnikiem pabaigos rinkmenos - -- htaccess trailing slash domainname Htaccess ukośnika nazwa_domeny - -- htaccess rewrite with end / Htaccess perrašyti su tikslu / - -- htaccess redirect trailing slash Htaccess peradresavimai ukośnika - -- rewrite trailing slash perrašyti ukośnika - -- rewriterule remove filename add slash RewriteRule ištrinti failo pridėti ukośnikiem - -- wordpress permalink "remove double" slash WordPress Nuolatinė "pašalinti dvigubą" įstrižas brūkšnys - --