Mod重写尾部斜杠问题

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

关于该主题的信息似乎并不多,所以我将概述我的特定问题,然后也许我们可以将问题和答案简化为更通用的内容.

There doesn't seem to be much info on this topic so I'm going to outline my specific problem then maybe we can shape the question and the answer into something a bit more universal.

我有这个重写规则

RewriteEngine On RewriteBase /bookkeepers/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/?$ index.php?franchise=$1

哪个将更改此URL

example/location/kings-lynn

进入这个

example/location/index.php?franchise=kings-lynn

我遇到的问题是,如果我添加斜杠

The problem I am having is that if I add a trailing slash

example/location/kings-lynn/

然后将查询字符串返回为

then the query string is returned as

franchise=kings-lynn/

,由于某种原因,我的CSS和Javascript文件均未加载.

and for some reason none of my CSS and Javascript files are being loaded.

有什么想法吗?

推荐答案

正如@Paul Tomblin所说,.+很贪婪;也就是说,它尽可能地匹配.

As @Paul Tomblin said, the .+ is being greedy; that is, it's matching as much as it can.

^(.+[^/])/?$告诉它匹配任何内容,后跟一个不是/的字符,然后是一个可选的/.这具有不捕获尾随/的效果.

^(.+[^/])/?$ tells it to match anything, followed by a character that isn't a /, then followed by an optional /. This has the effect of not capturing the trailing /.

CSS和Javascript不起作用的最可能原因是您使用的是相对路径,例如src ="my.js".当有斜杠时,它看起来像一个目录,因此您的浏览器将查找/location/kings-lynn/my.js.您只需使用文件的绝对路径(例如/location/my.js)即可解决此问题.

The most probable reason your CSS and Javascript doesn't work is you're using a relative path, like src="my.js". When there's a trailing slash, it looks like a directory, so your browser will look for /location/kings-lynn/my.js. You can fix this simply by using an absolute path to your files (e.g. /location/my.js).

更多推荐

Mod重写尾部斜杠问题

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

发布评论

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

>www.elefans.com

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