mod 重写(css/图像)
我使用以下内容重写我的网址:
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.+)\.html$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.+)$ $1.html
问题是这会导致 css 和图像不出现 - 有没有一种方法可以从 css 和图像文件夹等文件夹中排除规则,以便按应有的方式显示而不是死图像并且没有CSS? 谢谢天使xx
im using the following to rewrite my urls:
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.+)\.html$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.+)$ $1.html
the problem is this causes the css and images to not appear - is there a way that the rules can be excluded from folders like css and images folder so that the appear as they should instead of dead images and no css?
thanks Angel xx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最佳实践:
包含所有 css / 图像和 js 文件
当您应用
.htaccess
进行URL重写时,使用绝对路径而不是相对路径。Best Practice:
include all css / images and js files with
absolute path instead of relative path when you apply
.htaccess
for URL rewriting.尝试
用您的文件夹名称替换
css|images|js
,并用|
分隔希望这会有所帮助...
Try
Substitute
css|images|js
by your folder names, separated by|
Hope this helps...
将完整的域名放入 css 链接中:
to
当使用重写 url 时,您会得到目录:
yoururl.com/dir/dir/item.html
使 html 中的 css 文件路径不正确。如果您想避免这种情况,最好使用 css 文件的完整路径。您的浏览器不知道您正在重写网址,因此它认为您只是在浏览目录。
Put your complete domain in your css link:
to
When using rewrite url's you get directories:
yoururl.com/dir/dir/item.html
making the paths in your html to the css files incorrect.If you want to avoid this it's best to use complete paths to your css files. Your browser doesn't understand you are rewriting url's so it thinks that you are just browsing trough directories.
您可以更改
为
“/”作为主机上的根目录。与“/image/...”类似。
希望这有帮助...
You can change
To
"/" as root directory on your hosting. Similar with "/image/...".
Hope this helps...