开发者

Allow css through htaccess

开发者 https://www.devze.com 2023-03-14 01:17 出处:网络
Earlier I made a question about creating seo friendly urls. And I got the answer. Now I have a new problem. When I\'m using mod_rewrite in .htaccess file:

Earlier I made a question about creating seo friendly urls. And I got the answer.

Now I have a new problem. When I'm using mod_rewrite in .htaccess file:

RewriteEngine on
RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]

to create link like: www.myurl.com/page/11

It's working fine. But when im entering the new page with the new lovely URL, I'm not getting any CSS.

I think my .htaccess doesn't allow it.开发者_开发知识库 How do I allow this?


If you want to have cool URLs, you need to link your CSS/JS and image files from HTML with leading slash (/).

<script type="text/javascript" src="/js/web.js"></script>


You might have a look at the html page source how the CSS files are referenced. When rewriting URLs to something like /page/11 then for the browser it looks like you are using directories.

So, if your CSS files are referenced like

<link rel="stylesheet" type="text/css" href="css/stylesheet.css" />

then the browser looks for /page/css/stylesheet.css which of course does not exist.

To solve this, either add a rewrite rule for your CSS files to "undo" the path or change the reference to the CSS files to an absolute path.

<link rel="stylesheet" type="text/css" href="/css/stylesheet.css" />
0

精彩评论

暂无评论...
验证码 换一张
取 消