Add Trailing Slash to the End of the URL with .htaccess Rewrite Rules Thêm Trailing Slash đến cuối cùng của URL với. Htaccess Rewrite Nội quy
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. Để có một trang web có URL kết thúc bằng một slash (/), nó là một thực hành tốt để đảm bảo rằng tất cả các địa chỉ liên kết được phân tích cú pháp của các máy chủ trang web kết thúc với trailing slash, ngay cả khi khách truy cập để vào quên kết thúc slash. 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. Điều này tránh du khách được phục vụ với 404 Không tìm thấy trang này hay trang có thể không được hiển thị lỗi như một số trang web máy chủ xử lý các liên kết mà không có trailing slash như là một tên tập tin thay vì các thư mục, và vì vậy không thể tìm các tài liệu. 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. Nó cũng loại bỏ khả năng là cả hai trang với cùng một nội dung, một với slash ở cuối và khác mà không có, được xem như là của các công cụ tìm kiếm nội dung trùng lặp.
As an example, all hits to http://www.mydigitallife.info/contact should be redirect to http://www.mydigitallife.info/contact/. Ví dụ, tất cả các lần xem cho http://www.mydigitallife.info/contact nên được chuyển hướng đến 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. Hầu hết các máy chủ trang web, bao gồm cả việc phổ biến Apache HTTPD web hỗ trợ các mô-đun mod_rewrite, nơi quy định có thể được đặt trong. Htaccess tập tin để có thể chuyển hướng đến thêm trailing slash vào các URL mà không đã có một.
The following code can be put in .htaccess to redirect URL without trailing slash to URL with trailing slash: Dưới đây là những mã có thể được đặt vào. Htaccess để chuyển hướng mà không có địa chỉ URL của trailing slash đến với trailing slash:
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 hoặc
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 hoặc
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. Trong bạn đang sử dụng CMS hoặc blog như Wordpress cho phép URL tuỳ chỉnh cơ cấu cho permalinks, đặc biệt là tối ưu hóa cho công cụ tìm kiếm (SEO), các mã trên nên đến trước khi các khối ghi đè các điều kiện và quy định cho các URL tuỳ chỉnh cho các CMS hoặc blog nền tảng .
Brief explaination of the rewrite code to add trailing slash to URL Giới thiệu tóm tắt của các explaination ghi đè mã để thêm vào URL của trailing slash
RewriteEngine On - This line enables the runtime rewriting engine based on mod_rewrite module of Apache. RewriteEngine Ngày - Dòng này cho phép các động cơ runtime viết lại dựa trên mô-đun mod_rewrite của Apache.
RewriteBase / - This line sets the current page root directory as base URL for per-directory rewrites. RewriteBase / - Dòng này đặt ra những trang hiện thời thư mục gốc là cơ sở URL cho mỗi thư mục được ghi đè.
RewriteCond %{REQUEST_FILENAME} !-f - This line excludes all URLs pointing to existed files from been added with trailing slash again. RewriteCond% (REQUEST_FILENAME)!-F - Dòng này không bao gồm tất cả các URL trỏ đến từ các tập tin tồn tại được thêm với trailing slash lại. Directories cannot be excluded as this would exclude the rewrite behavior for existing directories. Thư mục không thể được loại trừ như thế này sẽ loại trừ các hành vi ghi đè cho các thư mục hiện hành.
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 - Dòng này là tùy chọn, và sẽ không bao gồm một mẫu URL (trong trường hợp này, index.php) mà người dùng không muốn nó được viết lại. Remove this line if not necessary. Hủy bỏ dòng này nếu không cần thiết.
RewriteCond %{REQUEST_URI} !\..+$ - Specify that the URL does not contain any . RewriteCond% (REQUEST_URI)! \ .. + $ - Chỉ định rằng URL không chứa bất kỳ. (dot) to exclude reference to file. (dấu chấm) để loại bỏ các tham chiếu đến tập tin này.
RewriteCond %{REQUEST_URI} !(.*)/$ - This line determines which URL doesn't contain a trailing slash RewriteCond% (REQUEST_URI) !(.*)/$ - Dòng này mà xác định địa chỉ không chứa một trailing slash
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] - Dòng này quá trình mà không có địa chỉ trailing slash mà đã thiết lập thông qua các điều kiện nêu trên, appending của một trailing slash và sau đó chuyển hướng với 301 hoặc vĩnh viễn tình trạng chuyển hướng đến URL mới. L mean this is the last line to process and the rewrite process can be terminated. L này có nghĩa là dòng cuối cùng để xử lý và quá trình ghi đè có thể được chấm dứt. Remember to replace the www.domain.com with your own domain name. Lưu thông tin để thay thế các www.domain.com với tên miền riêng của bạn.
Brief explaination for second set of rewrite rules and rule conditions Giới thiệu tóm tắt explaination cho lần thứ hai về ghi đè thiết lập quy tắc và quy định các điều kiện
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] - Dòng này chấm dứt các trailing slash appending quá trình ghi đè nếu URL đã có chứa các trailing slash.
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] +) - Dòng này xác định yêu cầu hiện không kết thúc bằng trailing slash.
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] - Dòng này nối thêm một slash vào cuối URI và 301 thường xuyên thực hiện một trang chuyển hướng đến URL mới với trailing slash, và chấm dứt việc ghi đè chặn.
IMPORTANT : The page is machine translated and provided "as is" without warranty. Lưu ý: Các trang web là máy tính dịch và cung cấp "như là" mà không có bảo hành. Machine translation may be difficult to understand. Máy dịch thuật có thể là khó hiểu. Please refer to Xin vui lòng tham khảo original English article Tiếng Anh bản gốc bài viết whenever possible. bất cứ khi nào có thể.
Related Articles Bài viết liên quan
- Redirect or Rewrite to Remove Double or Multiple Slashes (//) in URL Chuyển hướng hoặc Rewrite để Hủy bỏ đôi hoặc nhiều Slashes (/ /) trong URL
- SEO Friendly Rewrite Method to Move Website URL From Subdirectory to Root Parent Folder Thân thiện SEO Rewrite Phương pháp Chuyển URL của trang web Từ subdirectory vào thư mục gốc của Phụ Huynh
- D-Link Announced Price Slash on Entry Level 802.11n Wireless Router D-Liên kết công bố Giá bán Slash trên Entry Cấp bậc 802.11n Wireless Router
- WordPress Permalinks Does Not Work in xampp Setup WordPress Permalinks không hoạt động được thiết lập trong xampp
- Remove or Trim First or Last Few Characters in MySQL Database with SQL Hủy bỏ hoặc Trim đầu tiên hoặc lần cuối Một số ký tự trong cơ sở dữ liệu MySQL với SQL
- PHP Scripts open_basedir Restriction in Effect Error PHP Script open_basedir Restriction quả trong Lỗi
- Unable to Logon to Win2003 Domain AD Due to Windows Cannot Connect to the Domain Error Không thể Đăng nhập vào tên miền Win2003 AD Do Windows có thể không kết nối với tên miền Lỗi
- Google Domain Names Registration and Search for Free Apps for Your Domain Tên miền đăng ký của Google và tìm kiếm miễn phí cho các Apps cho tên miền của bạn
- Free .BIZ Domain Name Registration for 1 Year from 1&1 Internet (1and1.com) Miễn phí. BIZ Tên miền đăng ký cho 1 năm kể từ ngày 1 & 1 Internet (1and1.com)
- Fix Session Save Path Red Unwritable When Installing Joomla! Lưu Đường dẫn sửa phiên đỏ Unwritable Khi cài đặt Joomla!










































January 19th, 2009 19:50 19 tháng một, 2009 19:50
I'd been using that slash alot on one of my website. Tôi muốn được sử dụng mà slash rất nhiều vào một trong các trang web của tôi. 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. Hầu hết trong số họ đã được lập chỉ mục của công cụ tìm kiếm thành công, nhưng bốn người trong số họ trở lại là 404 không tìm thấy lỗi dựa trên báo cáo của Google Webmaster, wierd.
December 12th, 2008 12:53 12 tháng mười hai, 2008 12:53
I have tried both methods and they do work but not with the other statement that I have. Tôi đã thử cả hai phương pháp và những gì bạn làm công việc nhưng không phải với những tuyên bố khác mà tôi có. 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. Tôi đã tự hỏi chính xác những gì Killswitch có nghĩa là khi ông nói: "chơi với nó một chút." Tôi đã cố gắng sắp xếp lại trật tự và không có vẻ để giúp đỡ, tôi đang tìm một giải pháp nhanh chóng ở đây.
December 6th, 2008 10:37 6 tháng mười hai, 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. Điều này là cực kỳ hữu ích, tôi đã cố gắng cho các con số dài thời gian để hiểu cách thức để kết thúc một site.com / somthing để site.com / cái gì / mà không có may mắn. Had to play with it a bit due to the rules I already have, but had it working in about 5 mins. Đã có để chơi với nó một chút do các quy tắc tôi đã có, nhưng nó đã làm việc trong khoảng 5 phút.
October 31st, 2008 03:07 31 tháng mười, 2008 03:07
dlvrq rjdkq bfuwo jnlx dlvrq rjdkq bfuwo jnlx
July 26th, 2008 05:19 Tháng bảy 26, 2008 05:19
[...] Ä Ãm predÃdete aj problému Ä .2. [...] Ä predÃdete am 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. Pre htaccess som naÅ ¡iel peknà ½, ale anglickà ½ Ä là ¡NOK o tom, làm thế nào để thêm trailing slash vào cuối URL. Možnosti máte [...] MoÅ các nosti mà ¡te [...]