問題描述
我有一個網站,它有一個 index.php、幾個簡單的 .html 頁面和一個 .php 頁面(聯系表格)以及一個 .htaccess 文件.在我的網站上,我有指向頁面的按鈕,如下所示:index.php?p=welcome.php
(示例).如您所見,index.php
文件 includes
一個頁面,具體取決于 GET
傳遞的內容.
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
.
我寫了 .htaccess 來顯示:http://www.site.com/welcome/
而不是 http://www.sites.com/index.php?p=歡迎
.鏈接和重寫都有效.我遇到的唯一問題是當我單擊其中一個按鈕導航到另一個頁面時:沒有任何樣式.
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.
我已經測試過 index.php
文件是否正確地包含了其他頁面,并且確實如此.只是樣式表似乎不起作用.style.css
包含在它所屬的 index.php
文件的頂部.以下是我想向您展示的一些代碼:
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:
按鈕
<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.
推薦答案
如果使用相對路徑包含樣式表,那么這就是問題所在.嘗試使用:/path/to/style.css
而不是 relative/path/to/style.css
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
因此,如果您的樣式表位于 templates/style.css
中并且您如此引用它,那么當您重寫 URL http://www.site.com/index.php 時?page=welcome
到 http://www.site.com/welcome/
,樣式表的路徑是相對的:
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 后不加載樣式表并包含的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!