2013-03-08 72 views
1

當我試圖讓我的網站的網址乾淨,所以我創建了一個.htaccess文件如下工作:css文件停止使用.htaccess文件

Options +FollowSymLinks 
RewriteEngine On 

RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 

RewriteRule ^product/(\w+)/(\w+)$ product.php?id=$1 
RewriteRule ^product/(\w+)/(\w+)$ product.php?id=$1 

RewriteRule ^store/(\w+)/(\w+)$ Store.php?id=$1 
RewriteRule ^store/(\w+)/(\w+)$ Store.php?id=$1 

現在它工作正常,但是當我STRAT頁面我發現設計在沒有CSS和沒有圖像的情況下工作,所以你認爲是什麼問題?

最好的問候

+0

這取決於你的CSS和JS文件的位置。使用您的瀏覽器開發工具來查看瀏覽器在哪裏查找這些文件 – 2013-03-08 12:36:19

+0

我會說你的前兩條規則可能會制動CSS。嘗試將它們評論出來,看看會發生什麼。 – Ateszki 2013-03-08 12:42:12

+0

我試圖打開這個URL:http:// localhost/template/product/75/22 – test 2013-03-08 12:47:06

回答

2

問題可能是在您的CSS文件(和圖像等)的相對路徑。使用絕對路徑或基礎標籤在頭

<base href="http://www.example.com/" /> 
+0

我試了一下,瀏覽器仍然試圖加載它從失敗加載資源:服務器響應狀態404(未找到)http:///localhost/template/product/75/css/stylesheet.css 當我嘗試打開這個url:localhost/template/product/75/22 – test 2013-03-08 12:48:48

+0

並且在你的光盤路徑{localhost_root}/template/product/75/css/stylesheet.css是否存在? – 2013-03-08 12:58:22

+0

css位於{localhost_root} /template/css/stylesheet.css – test 2013-03-08 13:02:10

1

在HTML頁面中,前綴鏈接到你的CSS文件與/

所以,如果您有:

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

將其更改爲:

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

這使路徑CSS絕對的,所以它會發現CSS無論什麼「文件夾」瀏覽器認爲它是在。