关于该主题的信息似乎并不多,所以我将概述我的特定问题,然后也许我们可以将问题和答案简化为更通用的内容.
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重写尾部斜杠问题
发布评论