从htaccess的重写prevent CSS网址 [英] Prevent CSS URL from htaccess rewrite

查看:126
本文介绍了从htaccess的重写prevent CSS网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建一个标准的改写与的.htaccess 来做到这一点。

  

http://www.myurl.com/post/ {ID} /

 重写规则^交/([0-9] +)/ $ post.php中?ID = $ 1 [NC,L]
 

现在,它的作品完美,但所有其他外部URL(例如CSS和JavaScript)不工作,正确。 有没有一种方法,以prevent,而不必改变所有的网址是什么?我搜索在谷歌没有成功,任何想法?

解决方案

您将需要一个额外的规则来解决的CSS,JS,图片链接:

 #你重写规则
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^交/([0-9] +)/ $ post.php中?ID = $ 1 [QSA,NC,L]

#修复的CSS,JS,图片链接
重写规则^交/(+ \(?: JPE G |。?。?GIF | BMP | PNG | TIFF | CSS | JS))/ $ 1 [NC,L]
 

另外要确保只使用绝对路径在你的CSS,JS,图像文件,而不是相对的。这意味着你必须确保这些文件的路径开始无论是与的http:// 或斜线 /

I'm creating a standard rewrite with .htaccess to do this

http://www.myurl.com/post/{id}/

RewriteRule    ^post/([0-9]+)/?$    post.php?id=$1    [NC,L]

Now, it works perfectly but all others external URL ( for example CSS and JavaScript ) do not work, rightly. Is there a way to prevent it without having to change all the url ? I searched on Google without success, any ideas ?

解决方案

You will need an additional rule to fix css, js, images links:

# your rewrite rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^post/([0-9]+)/?$ post.php?id=$1 [QSA,NC,L]

# fix css, js, image links
RewriteRule ^post/(.+?\.(?:jpe?g|gif|bmp|png|tiff|css|js))$ /$1 [NC,L]

Alternatively make sure to 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 /

这篇关于从htaccess的重写prevent CSS网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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