问题描述
我基本试过低于这个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://本地主机/注册/注册/
,但如果我删除 / 从它到底给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的结尾斜杠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!