Add Trailing Slash to the End of the URL with .htaccess Rewrite Rules Pridať lomítko na konci URL s. Htaccess Prepis pravidiel
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. Pre webové stránky s adresami URL, ktoré končí lomítkom (/), je dobré praxe s cieľom zabezpečiť, aby všetky odkazy boli url analyzovaný webového servera skončil lomka, aj keď na to zabudnete zadať končí lomkou. 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. To zabránilo návštevníkov bola doručená s 404 Stránka nebola nájdená alebo nie je možné zobraziť chyba, pretože niektoré webové servery s odkazmi bez lomka ako názov súboru namiesto adresára, a preto nemohol nájsť dokumenty. 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. Je taktiež vylučuje možnosť, že obidve stránky s rovnakým obsahom, jeden s lomítkom na konci a na iné, bez toho, aby boli vnímané vyhladavacom ako duplicitné obsah.
As an example, all hits to http://www.mydigitallife.info/contact should be redirect to http://www.mydigitallife.info/contact/. Ako príklad možno uviesť, že všetky hity http://www.mydigitallife.info/contact to by sa malo presmerovať na 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. Most webového servera, vrátane populárnej webový server Apache httpd podporuje mod_rewrite modulu, kde pravidlá možno nastaviť. Htaccess, aby redirect pridať lomítko v URL, ktoré nie je ešte jeden.
The following code can be put in .htaccess to redirect URL without trailing slash to URL with trailing slash: Nasledujúci kód môže byť vo formáte. Htaccess presmerovať URL bez lomka URL s lomka:
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 alebo
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 alebo
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. V ste pomocou CMS alebo blog ako Wordpress, ktorý umožňuje vlastné URL štruktúru permalinks, predovšetkým pre optimalizácia pre vyhľadávače (SEO), na vyššie uvedené číslo by malo prísť do bloku prepísať podmienky a pravidlá pre URL prispôsobenie pre CMS alebo blog platform .
Brief explaination of the rewrite code to add trailing slash to URL Krátky explaination o prepísanie kódu pridáte lomka URL
RewriteEngine On - This line enables the runtime rewriting engine based on mod_rewrite module of Apache. RewriteEngine On - Táto položka umožňuje prepisovanie behu motora založená na mod_rewrite modul servera Apache.
RewriteBase / - This line sets the current page root directory as base URL for per-directory rewrites. RewriteBase / - táto položka nastaví aktuálnu stránku koreňovom adresári ako základňa pre URL per-adresár přepsání.
RewriteCond %{REQUEST_FILENAME} !-f - This line excludes all URLs pointing to existed files from been added with trailing slash again. RewriteCond% (REQUEST_FILENAME)!-F - Táto línia vylučuje všetky adresy URL ukazujúci na existovala súbory boli pridané s lomka znova. Directories cannot be excluded as this would exclude the rewrite behavior for existing directories. Adresáre nemôže byť vylúčená, pretože by to vylúčiť prepisovateľnú správania existujúcich adresárov.
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 - táto položka je voliteľná a bude vylučuje vzorky URL (v tomto prípade, index.php), že užívatelia nechcú, aby bol prepracovaný. Remove this line if not necessary. Odstráňte tento riadok nie je to nevyhnutné.
RewriteCond %{REQUEST_URI} !\..+$ - Specify that the URL does not contain any . RewriteCond% (REQUEST_URI)! \ .. + $ - Určuje, že URL neobsahuje. (dot) to exclude reference to file. (bodka) vylúčiť odkaz na súbor.
RewriteCond %{REQUEST_URI} !(.*)/$ - This line determines which URL doesn't contain a trailing slash RewriteCond% (REQUEST_URI) !(.*)/$ - Táto položka určuje, aké URL neobsahuje lomka
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] - Táto položka procesu URL bez lomka, ktoré prešlo podmienok stanovených vyššie, pridáte koncové lomka a potom presmerujte sa 301 alebo trvalý stav presmerovania na nové URL. L mean this is the last line to process and the rewrite process can be terminated. L znamenalo toto je posledný riadok na spracovanie a prepisovanie procesu môže byť zastavené. Remember to replace the www.domain.com with your own domain name. Nezabudnite nahradiť www.domain.com s vlastnou názov domény.
Brief explaination for second set of rewrite rules and rule conditions Krátky explaination pre druhý súbor prepísať pravidlá a pravidlo podmienky
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] - Tento riadok ukončí lomka pripájajúce prepisovanie procesu, ak URL už obsahuje lomka.
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] +) - Táto položka určuje, že žiadosť nie je končí lomka.
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] - Tento riadok append lomkou na konci URI a vykonať 301 trvalé presmerovanie na nové URL s lomka a ukončiť prepísať bloku.
IMPORTANT : The page is machine translated and provided "as is" without warranty. Upozornenie: Stránka je stroje preložené a poskytované "tak ako sú" bez záruky. Machine translation may be difficult to understand. Strojový preklad môže byť ťažké pochopiť. Please refer to Obráťte sa prosím na original English article Anglický originál článku whenever possible. kedykoľvek je to možné.
Related Articles Súvisiace články
- Redirect or Rewrite to Remove Double or Multiple Slashes (//) in URL Redirect alebo Rewrite odobrať dvoch alebo viacerých lomítka (/ /) do URL
- SEO Friendly Rewrite Method to Move Website URL From Subdirectory to Root Parent Folder SEO Friendly Rewrite Metóda Presun URL webovej stránky Od Potomok pre Root nadradeného priečinka
- D-Link Announced Price Slash on Entry Level 802.11n Wireless Router D-Link oznámila, Cena lomítka pri vstupe Level 802.11n Wireless Router
- WordPress Permalinks Does Not Work in xampp Setup WordPress Permalinks nefunguje v Xampp Setup
- Remove or Trim First or Last Few Characters in MySQL Database with SQL Odstráňte alebo Trim Prvý alebo pár znakov v MySQL databáze pomocou SQL
- PHP Scripts open_basedir Restriction in Effect Error PHP skripty open_basedir Obmedzenie Effect Chyba
- Unable to Logon to Win2003 Domain AD Due to Windows Cannot Connect to the Domain Error Nepodarilo sa prihlásení do domény Win2003 AD Kvôli Windows sa nemôže pripojiť k Domain Chyba
- Google Domain Names Registration and Search for Free Apps for Your Domain Google Doména Mená Registrácia a HĽadaŤ Voľný Apps pre vašu doménu
- Free .BIZ Domain Name Registration for 1 Year from 1&1 Internet (1and1.com) Bezplatne. BIZ Registrácia domény na 1 rok od 1 & 1 Internet (1and1.com)
- Fix Session Save Path Red Unwritable When Installing Joomla! Fix zasadnutí Uložiť Cesta Red Unwritable Kedy Inštalácia Joomla!










































January 19th, 2009 19:50 19. január 2009 19:50
I'd been using that slash alot on one of my website. Já bych byl pomocou lomítka, že veľa na jednom zo svojich webových stránok. 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. Väčšina z nich boli indexované vyhľadávači úspešne, ale štyri z nich vráti 404 nenašla chyby založený na Google Webmaster správy divný.
December 12th, 2008 12:53 12 december 2008 12:53
I have tried both methods and they do work but not with the other statement that I have. Som sa pokúsila obe metódy a robia prácu, ale nie s ostatnými, že som. 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. Hovoril som si, čo presne znamená, Killswitch, keď hovorí "hrať s ním trochu." Snažil som sa usporiadanie poradí, a že zrejme nie je pomoci, jsem hľadáte rýchle riešenie tu.
December 6th, 2008 10:37 6. decembra 2008 10:37
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. To bolo veľmi dôležité, som sa pokúšala o čo najdlhší čas na to, ako ukončiť site.com / somthing na site.com / niečo / bez šťastia. Had to play with it a bit due to the rules I already have, but had it working in about 5 mins. Musela hrať s ním trochu kvôli pravidlám už mám, ale už to pracuje asi 5 minút.
October 31st, 2008 03:07 31. októbra 2008 03:07
dlvrq rjdkq bfuwo jnlx dlvrq rjdkq bfuwo jnlx
July 26th, 2008 05:19 26. júl 2008 05:19
[...] Ä Ãm predÃdete aj problému Ä .2. [...] Ä am predÃdete aj problem © 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. Pre htaccess som naa ¡iel pekna ½, ale anglická ½ à la ¡NOK o tom, ako pridať lomítko na konci URL. Možnosti máte [...] MOA ¾ nosti ma ¡te [...]