Add Trailing Slash to the End of the URL with .htaccess Rewrite Rules הוסף נגררים Slash כדי בסוף כתובת עם. כללים השכתוב htaccess
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. עבור אתר אינטרנט יש כתובות המסתיימות נטוי (/), זה אימון טוב על מנת להבטיח כי כל הקישורים url כבר מנותח על ידי שרת האינטרנט הסתיימה עם קו נטוי נגרר, גם אם המבקרים לשכוח להיכנס לוכסן הסוף. 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. זה להימנע מבקרים הוגשה עם 404 דף לא נמצא או לא יכול להיות דף שגיאה הוצג כמו בשרתי אינטרנט לטפל קישורים ללא קו נטוי נגרר כשם קובץ בספרייה במקום, וכך הצליחה לאתר את המסמכים. 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. זה גם מבטל את האפשרות כי שני דפים עם תוכן זהה, אחד עם קו נטוי בסוף ועוד בלי, נתפסו על ידי מנועי חיפוש כפי תוכן כפולים.
As an example, all hits to http://www.mydigitallife.info/contact should be redirect to http://www.mydigitallife.info/contact/. כדוגמה, כל hits כדי http://www.mydigitallife.info/contact יש להפנות 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. רוב שרת אינטרנט, כולל שרת האינטרנט הפופולרי Apache httpd תומך mod_rewrite מודול שבו כללי ניתן להגדיר. קובץ htaccess כדי לנתב להוסיף קו נטוי נגרר אל כתובות זה לא כבר אחד.
The following code can be put in .htaccess to redirect URL without trailing slash to URL with trailing slash: את הקוד הבא ניתן לשים. Htaccess כדי לנתב מחדש את כתובת האתר ללא קו נטוי נגרר אל כתובת נגרר עם קו נטוי:
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 או
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 או
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. אתה משתמש ב-CMS או הבלוג כגון Wordpress המאפשר מבנה URL מותאם אישית עבור permalinks, במיוחד עבור אופטימיזציה למנועי חיפוש (SEO), את הקוד לעיל צריך לבוא לפני לחסום את השכתוב של תנאים וכללים עבור התאמה אישית של כתובת האתר או הבלוג פלטפורמת CMS .
Brief explaination of the rewrite code to add trailing slash to URL Explaination קצרה של לשכתב קוד כדי להוסיף קו נטוי נגרר אל כתובת
RewriteEngine On – This line enables the runtime rewriting engine based on mod_rewrite module of Apache. RewriteEngine ב - קו זה מאפשר Runtime שכתוב מנוע המבוסס על המודול mod_rewrite של אפאצ 'י.
RewriteBase / – This line sets the current page root directory as base URL for per-directory rewrites. RewriteBase / - שורה זו מגדירה את המדריך הנוכחי השורש דף ככתובת הבסיס לכל משכתב המדריך.
RewriteCond %{REQUEST_FILENAME} !-f – This line excludes all URLs pointing to existed files from been added with trailing slash again. RewriteCond% (REQUEST_FILENAME)!-F - שורה זו אינה כוללת את כל כתובות האתרים והצביע על קבצים התקיימה בין נוספו עם קו נטוי נגרר שוב. Directories cannot be excluded as this would exclude the rewrite behavior for existing directories. מדריכים לא יכול להיות שליליים כמו זה יהיה להוציא את לשכתב התנהגות עבור ספריות הקיימות.
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 - קו זה הוא אופציונלי, ויהיה כולל כתובת אתר לדוגמה (במקרה זה, index.php) כי משתמשים לא רוצה שזה יהיה מחדש. Remove this line if not necessary. הסר את הקו הזה אם לא הכרחי.
RewriteCond %{REQUEST_URI} !\..+$ – Specify that the URL does not contain any . RewriteCond% (REQUEST_URI)! \ .. + $ - לציין את כתובת האתר אינו מכיל. (dot) to exclude reference to file. (נקודה) כדי לכלול הפניה לקובץ.
RewriteCond %{REQUEST_URI} !(.*)/$ – This line determines which URL doesn't contain a trailing slash RewriteCond% (REQUEST_URI) !(.*)/$ - שורה זו קובעת את כתובת האתר אינו מכיל קו נטוי נגרר
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] - זו כתובת תהליך קו נטוי נגרר ללא תנאים שחלף מעל הגדר, על ידי צירוף קו נטוי נגרר ולאחר מכן כוון מחדש עם 301 או מעמד קבע מחדש לכתובת החדשה. L mean this is the last line to process and the rewrite process can be terminated. כלומר זו היא השורה האחרונה על מנת לעבד את התהליך מחדש יכולה להיפסק. Remember to replace the www.domain.com with your own domain name. זכור להחליף את www.domain.com עם בשם התחום שלך.
Brief explaination for second set of rewrite rules and rule conditions Explaination בקצרה על הסדרה השנייה של לשכתב כללים ותנאים שלטון
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] - זה קו נטוי נגרר מסיים את תהליך צירוף לשכתב את כתובת האתר אם כבר מכיל קו נטוי נגרר.
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] +) - שורה זו קובעת כי הבקשה אינה מסתיימת עם קו נטוי נגרר.
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] - שורה זו כדי להוסיף קו נטוי בסוף אורי לבצע הפניה 301 קבע לכתובת חדשה עם קו נטוי נגרר, וכן לסיים את השכתוב לחסום.
IMPORTANT : The page is machine translated and provided "as is" without warranty. חשוב: הדף מכונת תירגם מתפרסם "כמות שהוא" ללא אחריות. Machine translation may be difficult to understand. תרגום מכונה יכול להיות קשה להבין. Please refer to נא עיין original English article המאמר המקורי באנגלית whenever possible. בכל הזדמנות אפשרית.
Related Articles מאמרים קשורים
- Redirect or Rewrite to Remove Double or Multiple Slashes (//) in URL ניתוב מחדש או הסרה של השכתוב כדי פעמיים או חתכים מרובים (/ /) ב-URL
- SEO Friendly Rewrite Method to Move Website URL From Subdirectory to Root Parent Folder SEO ידידותית השכתוב שיטה אל העבר כתובת אתר מאת subdirectory כדי רוט Parent Folder
- Nintendo Plans on Price Slash for Wii to Compete Against Sony's PS3 and Microsoft's XBox נינטנדו מתכננת Wii מחיר Slash עבור להתחרות נגד ה PS3 של סוני ו-Microsoft's XBox
- Microsoft Confirmed Price Slash on Xbox Consoles to Stay Competitively in Gaming Segment מיקרוסופט אישרה המחיר סלאש על קונסולות Xbox כדי הישאר תחרותי המשחקים Segment
- AUO Plans to Slash e-Book Pricing to $100 by 2011 AUO תוכניות Slash דואר תמחור הספר עד $ 100 עד 2011
- D-Link Announced Price Slash on Entry Level 802.11n Wireless Router D-Link Slash מחיר הוכרז על Entry Level 802.11n נתב אלחוטי
- Remove or Trim First or Last Few Characters in MySQL Database with SQL להסיר או חתוך ראשית או דמויות האחרונים MySQL Database עם SQL
- WordPress Permalinks Does Not Work in xampp Setup וורדפרס Permalinks לא עובד ההתקנה xampp
- PHP Scripts open_basedir Restriction in Effect Error PHP הגבלת סקריפטים open_basedir למעשה שגיאה
- Unable to Logon to Win2003 Domain AD Due to Windows Cannot Connect to the Domain Error אין אפשרות כניסה ל Win2003 Domain לספירה בשל Windows אין אפשרות להתחבר שגיאה דומיין










































September 1st, 2009 00:47 1 ספטמבר 2009 00:47
Thanx. Thanx. Worked perfectly for me. עבד בצורה מושלמת בשבילי. Even wordpress uses the same code in .htaccess. גם וורדפרס משתמשת באותו קוד ב. Htaccess.
August 19th, 2009 07:07 19 אוגוסט 2009 07:07
Couldn't get the second option to work for me either. אין אפשרות לקבל את האפשרות השנייה לעבוד גם לי. Getting a 500 error. מקבל שגיאה 500.
January 19th, 2009 19:50 19 ינואר 2009 19:50
I'd been using that slash alot on one of my website. הייתי משתמש כי לוכסן הרבה על אחד באתר שלי. 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. רובם היו לאינדקס של מנוע החיפוש בהצלחה, אבל ארבעה מהם להחזיר שגיאה 404 לא נמצא על בסיס הדו"ח-Google Webmaster, מוזר.
December 12th, 2008 12:53 12 דצמבר 2008 12:53
I have tried both methods and they do work but not with the other statement that I have. ניסיתי את שתי השיטות והם עושים את העבודה אבל לא עם הקביעה אחרים שיש לי. 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. תהיתי מה בדיוק Killswitch מתכוון כשהוא אומר "לשחק עם זה קצת." ניסיתי לסדר מחדש את הסדר וזה לא נראה לעזור, אני מחפש פתרון מהיר כאן.
December 6th, 2008 10:37 6 דצמבר 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. זה היה מאוד מועיל, אני מנסה המון זמן להבין איך לסיים site.com / somthing כדי site.com / משהו / ללא הצלחה. Had to play with it a bit due to the rules I already have, but had it working in about 5 mins. צריך לשחק עם זה קצת בשל הכללים כבר יש לי, אבל זה היה עובד בערך 5 דקות.
October 31st, 2008 03:07 31 אוקטובר 2008 03:07
dlvrq rjdkq bfuwo jnlx dlvrq rjdkq bfuwo jnlx
July 26th, 2008 05:19 26 יולי 2008 05:19
[...] Ä Ãm predÃdete aj problému Ä .2. [...] יי am predÃdete AJ problà © יי מו .2. Pre htaccess som naÅ¡iel pekný, ale anglický Ä lánok o tom, how to add trailing slash to the end of the URL. סום קדם htaccess naa ¡iel peknà וחצי, אייל anglickà ½ à la ¡NOK O טום, כיצד להוסיף קו נטוי נגרר לסוף את כתובת האתר. Možnosti máte [...] מואה ¾ nosti ma ¡te [...]