htaccess的重写条件斜线只对特定目录 [英] .htaccess rewrite condition trailing slash only for specific directories

查看:115
本文介绍了htaccess的重写条件斜线只对特定目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的规则,它的伟大工程,并增加了斜线为我的网站上每个目录。 如何添加结尾的斜杠只有特定的目录如/场/?我不希望每个目录/路径有一个结尾的斜线。

 的RewriteCond%{REQUEST_URI} ^ / [^ \。] + [^ /] $
  重写规则^ $ HTTP(*)://%{HTTP_HOST} / $ 1 / [R = 301,L]
 

解决方案

 的RewriteCond%{REQUEST_URI} ^ /(课程|富|酒吧)$
重写规则^ $ HTTP(*)://%{HTTP_HOST} / $ 1 / [R = 301,L]
 

应工作,其中课程是要一个斜线添加到目录。

I have this rule which works great and adds a trailing slash for every directory on my site. How Can I add trailing slashes for only certain directories such /courses/ ? I don't want every directory / path to have a trailing slash.

  RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
  RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]

解决方案

RewriteCond %{REQUEST_URI} ^/(courses|foo|bar)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]

Should work where courses, foo and bar are directories that you want to add a trailing slash to.

这篇关于htaccess的重写条件斜线只对特定目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆