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.
Related Articles Susiję straipsniai
- Redirect or Rewrite to Remove Double or Multiple Slashes (//) in URL Peradresavimo ar perrašymas Ištrinti dvigubais arba trigubais nerijos bruožas (/ /) URL
- SEO Friendly Rewrite Method to Move Website URL From Subdirectory to Root Parent Folder SEO Friendly perrašymas būdas Perkelti URL iš Pakatalogį šaknies Parent Folder
- D-Link Announced Price Slash on Entry Level 802.11n Wireless Router D-Link announced Kaina slash dėl Entry Level 802.11n Wireless Router
- WordPress Permalinks Does Not Work in xampp Setup WordPress Nuolatiniai neveikia XAMPP Diegimas
- Remove or Trim First or Last Few Characters in MySQL Database with SQL Šalinti arba TRIMs Pirmasis ar pastaruosius keletą simbolių MySQL duomenų bazę su SQL
- PHP Scripts open_basedir Restriction in Effect Error PHP open_basedir Restriction in effect Klaida
- Unable to Logon to Win2003 Domain AD Due to Windows Cannot Connect to the Domain Error Nepavyko prisijungti prie Win2003 domeno AD Dėl Windows negali prisijungti prie domeno Klaida
- Google Domain Names Registration and Search for Free Apps for Your Domain "Google" domenų vardų registracija ir paieška Laisvas Apps jūsų domenui
- Free .BIZ Domain Name Registration for 1 Year from 1&1 Internet (1and1.com) Nemokamai. BIZ domeno vardo registracija 1 metų nuo 1 & 1 Internet (1and1.com)
- Fix Session Save Path Red Unwritable When Installing Joomla! Fix sesija Išsaugoti Kelias Raudonojo Unwritable Kai Diegimas Joomla!










































January 19th, 2009 19:50 Sausis 19th, 2009 19:50
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.
December 12th, 2008 12:53 Gruodis 12, 2008 12:53
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.
December 6th, 2008 10:37 6 gruodis 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. 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.
October 31st, 2008 03:07 October 31st, 2008 03:07
dlvrq rjdkq bfuwo jnlx dlvrq rjdkq bfuwo jnlx
July 26th, 2008 05:19 26 liepa 2008 05:19
[...] Ä Ã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 [...]