我想从author/$username重定向到author/$username/。$username是作者的用户名。
这是我的.htaccess内容:
RewriteEngine on
RewriteRule ^author/([A-Za-z0-9-\+]+)/?$ author/index.php?username=$1 [NC,L,QSA]
RewriteRule ^authorpost/([A-Za-z0-9-\+]+)/postid/([0-9]+)/?$ author/index.php?username=$1&postid=$2 [NC,L,QSA]我该怎么改呢?
发布于 2020-01-22 15:02:21
所以,如果我理解正确的话,您只需要在URL /author/<username>上附加一个斜杠
在.htaccess文件的顶部尝试这样的操作:
RewriteRule ^(author/[A-Za-z0-9+-]+)$ /$1/ [R=302,L]字符类中的+没有特殊意义,因此不需要转义。连字符(-)应该位于字符类的开头或结尾,以便匹配文字连字符(而不必转义)。
在下面的重写中,您现在可以强制使用尾随斜杠,而不是使它成为可选的。例如:
RewriteRule ^author/([A-Za-z0-9+-]+)/$ author/index.php?username=$1 [NC,L,QSA]摘要
RewriteEngine On
# Append trailing slash if omitted
RewriteRule ^(author/[A-Za-z0-9+-]+)$ /$1/ [NC,R=302,L]
# Internal rewrites...
RewriteRule ^author/([A-Za-z0-9+-]+)/$ author/index.php?username=$1 [NC,L,QSA]
RewriteRule ^authorpost/([A-Za-z0-9+-]+)/postid/([0-9]+)/?$ author/index.php?username=$1&postid=$2 [NC,L,QSA]理想情况下,您应该避免在内部重写时使用NC标志,以避免可能重复的内容。至少,这是不必要的。
https://stackoverflow.com/questions/59862013
复制相似问题