为什么我不能在我的重写规则斜线? [英] Why can't i have slashes in my rewrite rule?

查看:124
本文介绍了为什么我不能在我的重写规则斜线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个.htaccess文件,创建搜索引擎优化的URL。

I am trying to make an .htaccess file, to create SEO url.

看来不过,我不能在mod-rewrite斜线,我在做这错了吗?

It seems however that I can't have a slash in the mod rewrite, am I doing this wrong?

我的code是如下:

RewriteEngine on
RewriteRule ^(.+)/$ /$1 [L,R=301]
RewriteRule ^folder/folder-name index.php?show=folder&folder_id=7

在页面加载正确,但样式表/图像/未发现的JavaScript!

The page is loaded correctly, but the style sheet/images/javascript aren't found!

就好像,网页认为它应该寻找样式/图像/ JS相对于文件/文件夹名称。

It's as if, the page thinks that it should look for the style/images/js relative to "folder/folder-name".

如果我改变最后一行:

RewriteRule ^folder-folder-name index.php?show=folder&folder_id=7

那么一切都是正确加载,所以我pretty的肯定这是因为斜线。

Then everything is loaded correctly, so i'm pretty sure it's because of the slash.

任何帮助吗?

推荐答案

这是因为你用你的JS相对路径,CSS等,您有2个选项来解决这个问题:

It is because you're using relative paths in your JS, CSS etc. You have 2 options to fix it:

  1. 只需使用你的CSS,JS,图像文件,而不是一个相对的绝对路径。这意味着你必须确保这些文件的路径开始无论是与的http:// 或斜线 /
  2. 您可以尝试在你的页面的头部添加这个标签:

  1. Just use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with http:// or a slash /.
  2. You can try adding this tag in your page's header:

<base href="/" />

这篇关于为什么我不能在我的重写规则斜线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆