用尾随斜线符CSS / IMG / SCRIPTS mod_rewrite的路径 [英] mod_rewrite with Trailing Slash breaks CSS/IMG/SCRIPTS paths
问题描述
我试图使mod_rewrite对URL的第一个子目录字符串,以便为jsfiddle.net类/数据库内保存的URL创建类似的功能。该脚本工作正常,并不会改写。
I'm trying to make mod_rewrite the first sub-directory string from url in order to create similar functionality as 'jsfiddle.net saved url's within a class/db. The script works fine and does the rewrite.
例如。 URL的
http://jsfiddle.net/RyEue/
这工作正常(加载所有的CSS,脚本等):
This works fine (loads all css, scripts, etc.):
http://www.domain.com/787HHJ2
这是我在这做的伎俩过去的习惯。
This is what I've used in the past which does the trick.
截至去年斜线,脚本,CSS和其他松散的路径URL时出了问题。
http://www.domain.com/787HHJ2/
改写脚本:
DirectoryIndex index.php index.html
Options +FollowSymlinks
RewriteEngine On # Turn on the rewriting engine
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !.
RewriteRule ^.+/?$ index.php [QSA,L]
不能确定这是否与的RewriteBase做的,我尝试过多种方式。
Unsure if this has to do with Rewritebase, I've tried multiple ways.
PS。我试着设置路径绝对(例如SRC =/ IMG / theimage.jpg)没有运气。
PS. I've tried setting paths to absolute (e.g. src="/img/theimage.jpg") without luck.
推荐答案
1。请确保您有CSS /图像/ JS等相对于根文件夹链接(与领先的斜线): /styles/main.css
1. Make sure you have css/images/js etc linked relative to root folder (with leading slash): /styles/main.css
2。添加这些ruls的一个前当前的:
2. Add one of these ruls before current one:
# do not touch files with .css/.js/.jpg etc extensions
RewriteRule \.(css|js|jpg|png|gif)$ - [L]
或
# do not touch any resources in images/css/js folders
RewriteRule ^(images|css|js)/ - [L]
3。清除浏览器缓存和(这带来了很多困惑,当重写规则是固定的,有时浏览器可能显示缓存页/资源)重新启动。
3. Clear browser caches and restart (sometimes browser may display cached page/resource when rewrite rule was fixed which brings a lot of confusion).
这篇关于用尾随斜线符CSS / IMG / SCRIPTS mod_rewrite的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!