20

我需要对以下重写规则做些什么才能使其生效,无论它们是否是 URL 末尾的斜杠?

IE。 http://mydomain.com/content/featuredhttp://mydomain.com/content/featured/

RewriteRule ^content/featured/ /content/today.html 
4

2 回答 2

35

使用$标记字符串的结尾,使用?标记前面的表达式重复零次或一次:

RewriteRule ^content/featured/?$ content/today.html

但我建议您坚持使用一种符号并纠正拼写错误:

# remove trailing slashes
RewriteRule (.*)/$ $1 [L,R=301]

# add trailing slashes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ $0/ [L,R=301]
于 2009-02-12T08:45:57.513 回答
4

简单的方法:

RewriteEngine On
RewriteBase / 
RewriteRule ^content/featured(\/||)$ /content/today.html [L,R=301,NC] 
于 2013-08-06T04:50:16.630 回答