我需要对以下重写规则做些什么才能使其生效,无论它们是否是 URL 末尾的斜杠?
IE。 http://mydomain.com/content/featured 或 http://mydomain.com/content/featured/
RewriteRule ^content/featured/ /content/today.html
我需要对以下重写规则做些什么才能使其生效,无论它们是否是 URL 末尾的斜杠?
IE。 http://mydomain.com/content/featured 或 http://mydomain.com/content/featured/
RewriteRule ^content/featured/ /content/today.html
使用$
标记字符串的结尾,使用?
标记前面的表达式重复零次或一次:
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]
简单的方法:
RewriteEngine On
RewriteBase /
RewriteRule ^content/featured(\/||)$ /content/today.html [L,R=301,NC]