样式表在使用RewriteRule和包含后不加载 [英] Stylesheet does not load after using RewriteRule and include

查看:103
本文介绍了样式表在使用RewriteRule和包含后不加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,它有一个index.php,几个简单的.html页面和一个.php页面(联系表)以及一个.htaccess文件。在我的网站上,我有按钮指向页面,如下所示: index.php?p = welcome.php (示例)。如您所见, index.php 文件包含页面,具体取决于<$ c传递的内容$ c> GET 。



我写了.htaccess来显示: http://www.site .com / welcome / 而不是 http://www.sites.com/index.php?p=welcome 。链接并重写这两个工作。我遇到的唯一问题是,当我点击其中一个按钮导航到另一个页面时:没有任何样式。



我已经测试过是否存在 index.php 文件正确地包含其他页面,并且它的确如此。这只是样式表,似乎没有工作。 style.css 包含在它所属的 index.php 文件的顶部。以下是我想要展示的代码片段:

按钮

 <表> 
< tr>
< td>< a href =/ welcome />< div>欢迎< / div>< / a>< / td>
< / tr>
< tr>
< td>< a href =/ references />< div>参考文献< / div>< / td>< / a>
< / tr>
< tr>
< td>< a href =/ aboutme />< div>关于我< / div>< / td>< / a>
< / tr>
< tr>
< td>< a href =/ contact />< div>联络人< / div>< / td>< / a>
< / tr>
< / table>

.htaccess

  RewriteEngine On 
RewriteRule ^([az] +)/ $ index.php?p = $ 1

为了说清楚:网站仍然像通常那样运行,但它并不适用样式表中的任何样式。任何帮助将不胜感激。 解决方案

如果使用相对路径包含样式表,那将是问题所在。尝试使用: /path/to/style.css 而不是 relative / path / to / style.css templates / style.css 中,并且您引用它,那么当您重写URL< / code& code> http://www.site.com/index.php?page=welcome 至 http://www.site.com/welcome/ code>,样式表的路径与此相关:



http://www.site.com/welcome/templates/style .css


I have a website that has an index.php, a few simple .html pages and one .php page (contact form) as well as a .htaccess file. On my website I have buttons that point to the pages as follows: index.php?p=welcome.php (example). As you can see, the index.php file includes a page, depending on what was passed on by GET.

I've written the .htaccess to show: http://www.site.com/welcome/ instead of http://www.sites.com/index.php?p=welcome. The links and rewrite both work. The only problem I have is when I click one of the buttons to navigate to another page: there is no styling whatsoever.

I've tested to see if the index.php file is including the other pages properly, and it does. It's just the stylesheet that doesn't seem to work. The style.css is included at the top of the index.php file, where it belongs. Here are bits of code I'd like to show you:

Buttons

<table>
    <tr>
        <td><a href="/welcome/"><div>Welcome</div></a></td>
    </tr>
    <tr>
        <td><a href="/references/"><div>References</div></td></a>
    </tr>
    <tr>
        <td><a href="/aboutme/"><div>About me</div></td></a>
    </tr>
    <tr>
        <td><a href="/contact/"><div>Contact</div></td></a>
    </tr>
</table>

.htaccess

RewriteEngine On
RewriteRule ^([a-z]+)/$ index.php?p=$1

To make it clear: the site still functions as it normally does, but it just does not apply any styling from the stylesheet. Any help would be much appreciated.

解决方案

If the stylesheet is being included using a relative path, then that would be the problem. Try using: /path/to/style.css rather than relative/path/to/style.css

So if your stylesheet lives in templates/style.css and you reference it as such, when you rewrite the URL http://www.site.com/index.php?page=welcome to http://www.site.com/welcome/, the stylesheet's path is relative to that:

http://www.site.com/welcome/templates/style.css

这篇关于样式表在使用RewriteRule和包含后不加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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