Add Trailing Slash to the End of the URL with .htaccess Rewrite Rules添加斜線到去年底的網址。 htaccess的重寫規則
For a website that has URLs that end with a slash (/), it’sa 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鏈接被解析由Web伺服器結束與斜線,即使遊客別忘了輸入結束斜線。 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/.作為一個例子,所有的點擊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.大多數的Web伺服器,包括流行的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的重定向URL無斜線的網址與斜線:
RewriteEngine On關於rewriteengine
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元/ [升時, 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 ,升]
or或
RewriteEngine On關於rewriteengine
RewriteBase / rewritebase /
RewriteRule ^([a-zA-Z0-9]+)/$ /$1 [L] rewriterule ^ ( [一-雜z0 - 9 ]+)/$ / $ 1 [升]
RewriteCond %{THE_REQUEST} ^[AZ]{3,9}\ /([a-zA-Z0-9]+) rewritecond % ( the_request ) ^ [排序: ( 3,9 ) \ / ( [一-雜z0 - 9 ] + )
RewriteRule ^([a-zA-Z0-9]+)$ /%1/? rewriterule ^ ( [一-雜z0 - 9 ] + ) $ / % 1 / ? [R=301,L] [ r = 301 ,升]
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.在您使用的細胞質雄性不育或博客等的WordPress ,允許自定義網址為永久性結構,特別是搜索引擎優化( SEO ) ,上面的代碼應該來之前塊重寫條件和規則的URL定制的CMS或博客平台。
Brief explaination of the rewrite code to add trailing slash to URL 簡短的闡釋重寫代碼添加斜線網址
RewriteEngine On - This line enables the runtime rewriting engine based on mod_rewrite module of Apache. rewriteengine上-這條線,使運行時重寫引擎的基礎上m od_rewrite模塊的A pache。
RewriteBase / - This line sets the current page root directory as base URL for per-directory rewrites. rewritebase / -這條線集當前頁的根目錄為基礎的U RL為每目錄重寫。
RewriteCond %{REQUEST_FILENAME} !-f - This line excludes all URLs pointing to existed files from been added with trailing slash again. rewritecond % ( request_filename ) ! - F的-這條線不包括所有的U RL指向存在的文件從,增加了斜線。 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 -這條線是可選的,將不包括示例網址(在這種情況下,的i ndex.php)表示,用戶不希望它被改寫。 Remove this line if not necessary.刪除此行,如果沒有必要的。
RewriteCond %{REQUEST_URI} !\..+$ - Specify that the URL does not contain any . rewritecond % ( request_uri ) ! \ .. +美元-指定該U RL不包含任何。 (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元/ [升時, R = 301 ] -這條線的過程中的U RL沒有結尾的斜線表示,已通過上述條件,附加一斜線,然後重定向301或永久重定向的地位,以新的URL 。 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 簡短的解釋,為第二組重寫規則和法治的條件
RewriteRule ^([a-zA-Z0-9]+)/$ /$1 [L] - This line terminates the trailing slash appending rewrite process if the URL already contains trailing slash. rewriterule ^ ( [一-雜z0 - 9 ]+)/$ / $ 1 [升] -此行終止斜線附加重寫的過程中如果U RL已經包含斜線。
RewriteCond %{THE_REQUEST} ^[AZ]{3,9}\ /([a-zA-Z0-9]+) - This line determines request that does not ends with trailing slash. rewritecond % ( the_request ) ^ [排序: ( 3,9 ) \ / ( [一-雜z0 - 9 ] + ) -這條線決定的要求,這並不完與斜線。
RewriteRule ^([a-zA-Z0-9]+)$ /%1/? rewriterule ^ ( [一-雜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 ,升] -這條線附加一個斜線,到去年底, U RI和執行3 01永久重定向到新的U RL與斜線,並終止重寫座。
IMPORTANT : This is a machine translated page which is provided "as is" without warranty. 重要說明 :這是一個機器翻譯網頁是“按原樣”提供的擔保。 Machine translation may be difficult to understand.機器翻譯可能很難理解。 Please refer to請參閱 original English article英文原版的文章 whenever possible.只要有可能。
Share and contribute or get technical support and help at分享和貢獻,或取得技術的支持和幫助,在 My Digital Life Forums 我的數字生活論壇 . 。
Related Articles相關文章
- Redirect or Rewrite to Remove Double or Multiple Slashes (//) in URL重定向或重寫,以消除雙重或多重斜線( / / )在網址
- SEO Friendly Rewrite Method to Move Website URL From Subdirectory to Root Parent Folder徐友好重寫方法動議網址從子目錄,以根父文件夾
- Remove and Uninstall or Disable ModSecurity (mod_security)刪除和卸載或禁用modsecurity ( mod_security )
- WordPress Permalinks Does Not Work in xampp Setup在WordPress永久不工作, xampp安裝
- Remove or Trim First or Last Few Characters in MySQL Database with SQL刪除或修剪第一或過去數字符在MySQL數據庫與SQL
- How to Move WordPress Blog to New Domain or Location如何移動的WordPress所博客新的網域或位置
- Fix Session Save Path Red Unwritable When Installing Joomla!修正會議儲存路徑紅色unwritable安裝時, joomla !
- How to Add a MySpace User As Friend in Friends List如何添加MySpace上的用戶為朋友在好友列表
- How to Activate and Use FeedBurner MyBrand for Free如何激活和使用feedburner mybrand為免費
- How to Add and Put Picture or Image in MySpace Comment如何添加和付諸表決,圖片或影像在MySpace上評論



















July 26th, 2008 05:19 2008年7月26日5時19分
[...] Ä Ãm predÃdete aj problému Ä .2. [ … … ] ä ãm predãdete的AJ problã © ä 0.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的第一次高級官員會議naå ¡ iel peknã半,的ALE anglickã ½ ä lã ¡挪威克朗o湯姆,如何添加斜線到去年底,該網址。 Možnosti máte [...] moå ¾諾斯蒂mã ¡特[ … … ]