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