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 我的數字生活論壇 .



One Response to “Add Trailing Slash to the End of the URL with .htaccess Rewrite Rules” 1回應“添加斜線到去年底的網址。 htaccess的重寫規則”

  1. Na SEO muÅ¡ke - Vybrali.sme.sk a ukonÄ ujúce lomeno v URL | SEO chat娜徐muå ¡克-v ybrali.sme.sk一u konäu jãº行政長官l omenov網址|徐聊天
    July 26th, 2008 05:19 2008年7月26日5時19分
    1

    [...] Ä Ã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ã ¡特[ … … ]

Leave a Reply離開的答复

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> 您可以使用這些標籤:的<a href="" title=""> <abbr title=""> <acronym title="">的<b> <blockquote cite=""> <cite>的<code> <刪除日期時間= “ ” >的<em>的<i> <q cite=""> <strike>的<strong>

Subscribe without commenting訂閱無評論


Custom Search

New Articles新的條款,

Incoming Search Terms for the Article傳入的搜索條件文章

mod rewrite trailing slash 按付款當日價格計算重寫斜線 - - mod rewrite add slash 按付款當日價格計算重寫添加斜線 - - mod_rewrite add trailing slash mod_rewrite添加斜線 - - mod_rewrite append slash mod_rewrite附加斜線 - - mod_rewrite add slash mod_rewrite添加斜線 - - 301 trailing slash 301斜線 - - mod rewrite add trailing slash 按付款當日價格計算重寫添加斜線 - - php htaccess urls slash PHP的htaccess的網址斜線 - - trailing slash htaccess 斜線htaccess的 - - trailing slash 斜線 - - .htaccess add trailing slash 。 htaccess的添加斜線 - - rewriterule add trailing slash rewriterule添加斜線 - - htaccess redirect slash htaccess的重定向斜線 - - mod_rewrite append trailing slash mod_rewrite附加斜線 - - apache rewrite trailing slash 阿帕奇重寫斜線 - - wordpress add slash at end of url 在WordPress添加斜線在年底網址 - - apache rewrite add trailing slash 阿帕奇重寫添加斜線 - - how to remove multiple slashes from domain 如何刪除多個斜線從網域 - - rewriterule trailing slash rewriterule斜線 - - mod rewrite append trailing slash 按付款當日價格計算重寫附加斜線 - - RewriteRule slash rewriterule斜線 - - directory slash rewrite 目錄斜線重寫 - - htaccess remove trailing slash htaccess的刪除斜線 - - RewriteRule fix trailing slash rewriterule修復斜線 - - apache rewrite add slash 阿帕奇重寫添加斜線 - - mod rewrite optional trailing slash 按付款當日價格計算重寫可選斜線 - - "add slash" htaccess “添加斜線” htaccess的 - - rewrite url trailing slash 重寫網址斜線 - - wordpress trailing slash url 在WordPress斜線網址 - - htaccess redirect trailing slash htaccess的重定向斜線 - - php slash url PHP的斜線網址 - - htaccess add trailing slash htaccess的添加斜線 - - apache slash at end of url 阿帕奇斜線在年底網址 - - mod_rewrite slash mod_rewrite斜線 - - mod_rewrite remove trailing slash mod_rewrite刪除斜線 - - php + rewrite + add trailing slash PHP中+改寫+添加斜線 - - rewrite add trailing slash 重寫添加斜線 - - seo trailing slash 徐斜線 - - url trailing slash 網址斜線 - - rewrite htaccess add slash htaccess的重寫添加斜線 - - htaccess ending slash htaccess的結束斜線 - - remove trailing slash htaccess 刪除斜線htaccess的 - - rewrite add trailing slash to url 重寫添加斜線網址 - - rewrite trailing slash 重寫斜線 - - mod_rewrite slash at the end mod_rewrite斜線在年底 - - htaccess add trailing slash directory htaccess的添加斜線目錄 - - php remove trailing slash PHP中刪除斜線 - - add slash rewrite 添加斜線重寫 - - apache add slash 阿帕奇添加斜線 - - apache redirect trailing slash 阿帕奇重定向斜線 - -