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添加斜线在年底网址 - - joomla remove trailing slash joomla删除斜线 - - apache rewrite add trailing slash 阿帕奇重写添加斜线 - - how to remove multiple slashes from domain 如何删除多个斜线从网域 - - rewriterule trailing slash rewriterule斜线 - - mod rewrite append trailing slash 按付款当日价格计算重写附加斜线 - - url 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 slash htaccess的添加斜线 - - 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 徐斜线 - - 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 添加斜线重写 - -