2014-01-12 56 views
0

我想在有人呼叫像example.com/page/3fssdfs這樣的url時重定向URL,因此我會使用下面的htaccess代碼,它就像page?id = 3fssdfs。當使用htaccess重寫URL時,內容文件不起作用

RewriteRule ^page/([A-Za-z0-9-]+)/?$ page.php?id=$1 

因此,當有人訪問example.com/page/3fssdfs時,頁面加載正常。但是CSS和圖像文件不會加載。當我檢查他們出現這樣的控制檯,

GET http://example.com/page/assets/css/index.css 404 (Not Found) 

的CSS文件被存放像example.com/assets

所以,我怎麼能修復這個錯誤?在這裏感謝

UPDATE是完整的.htaccess文件

RewriteEngine on 
RewriteBase/

#if the file does NOT exist (! means NOT, and -f means file exists) 
RewriteCond %{REQUEST_FILENAME} !-f 
#if the directory does NOT exit (-d stands for directory exists) 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^page/([A-Za-z0-9-]+)/?$ page.php?id=$1 

RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^([^\.]+)$ $1.php [NC] 

RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^([^\.]+)$ $1.html [NC]' 
+0

你想做什麼?不應該'page/assets/css/index.css'爲'/ assets/css/index.css'?或者你想獲得像'?page =/assets/css/index.css'這樣的東西 – Gasim

+0

@Gasim css文件位於根文件夾中,並且在URL重寫編輯後,url看起來像example.com/page/123和服務器認爲CSS文件是在頁面/ css /不在根文件夾 – rksh

+0

@Gasim把它簡單我需要加載的CSS文件,CSS文件不加載,因爲頁面認爲CSS文件在一個不同的文件夾稱爲頁面,但它不是。頁面只是一個url重寫路徑。 – rksh

回答

1

添加一個重寫條件:

#if the file does NOT exist (! means NOT, and -f means file exists) 
RewriteCond %{REQUEST_FILENAME} !-f 
#if the directory does NOT exit (-d stands for directory exists) 
RewriteCond %{REQUEST_FILENAME} !-d` 

你重寫規則之前。

如果上述兩個條件成立,您的規則將被重寫;如果沒有,則不會有任何重寫,並且您將能夠訪問內容文件。

+0

恐怕問題仍然是一樣的。這裏是完整的.htaccess文件 – rksh