问题描述
我基本上尝试了下面的这个 mode_rewrite 规则.它的末尾有一个斜杠,但我希望它无论末尾是否有斜杠都可以工作.基本上我希望它像这样,因为有些人认为它在末尾带有斜杠是正常的,而其他人则不这么认为,因此无论它是否存在,我都希望它工作.
I basically tried this mode_rewrite rule below. It works with a slash on the end but I want it to work whether it has a trailing slash on the end or not. Basically I want it like this as some people see it as normal with a slash on the end and others don't hence why I want it to work whether it's there or not.
RewriteRule ^signup/register(.[^/]*) /signup/register.php [NC]
基本上它会像 http://localhost/signup/register/
一样工作,但如果我从末尾删除 / 会出现 404 错误.
Basically it will work like http://localhost/signup/register/
but if I remove the / from the end it gives 404 error.
推荐答案
子模式 .[^/]*
需要至少一个任意字符.在您的情况下,它可能是尾部斜杠.
The subpattern .[^/]*
requires at least one arbitrary character. In your case it’s probably that trailing slash.
您最好坚持一种书写方式(带或不带斜杠)并将错误的书写方式重定向到正确的书写方式,例如:
You should better stick to one writing (either with or without trailing slash) and redirect th wrong writing to the proper, like:
# remove trailing slash
RewriteRule ^(.*)/$ /$1 [L,R=301]
# add trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*[^/]$ /$0/ [L,R=301]
这篇关于模式重写;url末尾有/没有斜杠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!