模式重写;有/无对URL的结尾斜杠?

编程入门 行业动态 更新时间:2024-10-23 15:28:17
本文介绍了模式重写;有/无对URL的结尾斜杠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我基本试过低于这个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 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的结尾斜杠?

本文发布于:2023-11-01 20:24:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550321.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:斜杠   重写   结尾   模式   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!