我最近開始使用.htaccess url重寫,目前我正面臨一個問題。資源的位置與URL無關(.htaccess url rewrite)
我的文件夾結構是這樣的:
- 的index.php
- htaccess的
- 圖像/
- CSS/
- JS/
- 功能/
我的網站l通過做所有頁面
index.php?page=register
其中我的頁面位於函數映射。
的問題是,當我把這個在我的.htaccess
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^register/?$ index.php?page=register [NC,L] # Handle login page request
RewriteRule ^profile/([0-9]+)/?$ index.php?page=profile&member_id=$1 [NC,L] # Handle profile page request
當我瀏覽到
<website>/register/
我的CSS文件位於
../css/style.css
但是當我導航到
<website>/profile/1/
我的CSS文件位於
../../css/custom.css
如何確保頁面總是加載從
css/custom.css
我的文件是存在的,也許是提到的index.php的位置的變量?所以,我可以做
<link rel="stylesheet" type="text/css" href="<?= $variable ?>/css/custom.css" />
我在Windows上使用XAMPP(最新版本)
和網站將在基於Linux的Web服務器發佈。
如果您需要更多關於我的實施的信息,我現在無法想象,我會分享它。
修改.htaccess以將所有css請求重定向到您的css目錄。我想你還需要添加一個RewriteCond。 – Chad 2014-10-27 12:25:59