重定向目录的default.html怎么写,有条件重定向目录结构的URL到HTML文件

你在大多数地方正确的想法,但你需要改变你的规则的顺序不太具体的东西之前,以匹配更具体的东西。通常,我允许在下面的规则中通过/?在尾部/。如果您不允许匹配尾部/,请从头到尾将其删除。

RewriteEngine on

RewriteBase/

# This should be fine as you have it....

## If the request is for a valid directory, file, or link, don't do anything

RewriteCond %{REQUEST_FILENAME} -d [OR]

RewriteCond %{REQUEST_FILENAME} -f [OR]

RewriteCond %{REQUEST_FILENAME} -l

RewriteRule^- [L]

# Reverse your rule order here.

# First match name1|name2 with an optional trailing/

# but nothing else following...

RewriteRule ^(name1|name2)/?$ main.php?g1=$1 [L,QSA]

# Two additional dirs

RewriteRule ^(name1|name2)/([^/]+)/([^/]+)/?$ main.php?g1=$1&g2=$2&g3=$3 [L,QSA]

# Three additional dirs

RewriteRule ^(name1|name2)/([^/]+)/([^/]+)/([^/]+)/?$ main.php?g1=$1&g2=$2&g3=$3&g4=$4 [L,QSA]

# Last, do the generic rule to rewrite to .html

# using [^.]+ to match anything not including a .

# You could be more specific with something like [a-z]+ if that

# corresponds to your expected input

RewriteRule ^([^.]+)$ $1.html [L,QSA]

如果你想检查URI是没有条件name1, name2,使用[AND]这是隐式:

RewriteCond %{REQUEST_URI} !/name1

RewriteCond %{REQUEST_URI} !/name2

RewriteRule ^([^.]+)$ $1.html [L,QSA]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值