2013-10-24 68 views
0

我有一個htaccess文件,我嘗試重寫,但它導致我多個問題。首先這裏是我的htacess文件:Htaccess:更改根目錄並沒有找到文件

RewriteEngine On 

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

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ http://%1/ [R=301,L] 

RewriteRule ^([a-zA-Z0-9]*)/?$ index.php?category=$1&%{QUERY_STRING} 
RewriteRule ^([a-zA-Z0-9]*)/([a-zA-Z0-9]+)/?$ index.php?category=$1&itemId=$2&%{QUERY_STRING} 

RewriteRule ^login$ login.php?category=$1&%{QUERY_STRING} [L] 

的第一個問題是,當我做出這樣「mysite的/富/酒吧/」的請求時,它重寫類的itemId查詢字符串,但它也改變了基地目錄爲我的css文件和Js文件到/foo/bar/design/css/style.css

第二個問題是我有幾個路徑像「登錄/」,「註冊/」,「用戶/」 ,當我嘗試加載相應的文件,它說:

The requested URL /login/ was not found on this server. 

感謝您的幫助!

回答

0

首先改變你的.htaccess這樣的:

RewriteEngine On 

## If the request is for a valid directory 
RewriteCond %{REQUEST_FILENAME} -d [OR] 
## If the request is for a valid file 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
## don't do anything 
RewriteRule^- [L] 

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ http://%1/ [R=301,L] 

RewriteRule ^([a-zA-Z0-9]*)/?$ index.php?category=$1 [L,QSA] 
RewriteRule ^([a-zA-Z0-9]*)/([a-zA-Z0-9]+)/?$ index.php?category=$1&itemId=$2 [L,QSA] 

RewriteRule ^login/?$ login.php?category=$1&%{QUERY_STRING} [L,QSA] 
+0

現在,任何路徑顯示錯誤... – Cedric

+0

網址是哪出錯誤,什麼是錯誤? – anubhava

+0

例如mysite.com/foo/bar/只是說沒有找到請求url – Cedric