使用htaccess重写规则重定向后不加载CSS [英] CSS not loading after redirect with htaccess rewrite rule

查看:164
本文介绍了使用htaccess重写规则重定向后不加载CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下用户个人资料网址的简写

  RewriteRule ^(\w +)/?$。 /profile.php?name_of_user=$1 

当我做 site.com/name_of_user



但不适用于 site.com/name_of_user/



虽然重定向到正确的页面...



解决方案

解决这个问题最简单的方法是指定CSS文件的完整路径在


$ b $ p

如果您的mod_rewrite规则正在修改您的CSS文件的路径,想要将它放在 RewriteRule 之前:

  RewriteCond%{REQUEST_FILENAME} !-f 

这样可以确保请求与重写前的文件不匹配。 p>

I have the following Short-hand for a user profile url

RewriteRule ^(\w+)/?$ ./profile.php?name_of_user=$1

The site is styled with the appropriate css file when i do site.com/name_of_user

but not when i do site.com/name_of_user/

Although the redirect is to the right page...

Help is appreciated!

解决方案

the easiest way to fix this is to specify the full path to your CSS file in the <head> of the HTML file.

If your mod_rewrite rule is modifying the path to where your CSS file is, you'd also want to place this before your RewriteRule:

RewriteCond %{REQUEST_FILENAME} !-f

This makes sure that the request doesn't match a file before rewriting it.

这篇关于使用htaccess重写规则重定向后不加载CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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