2012-10-31 26 views
1

我所在的文件夾中的.htaccess文件「/混音帶/」我試圖獲取URL mydomain.com/music/downloads/mixtapes/this-title/id執行mydomain.com/music/downloads/mixtapes/item.php?title=variable1&id=variable2有2個變量與重寫規則「/」分隔

目前我有以下方式有點工作,但它只使用id和我需要兩個變量(../mixtapes/title/id)分開「/」和由於某種原因與下面的代碼索引頁面「/ mixtapes /」不行,我很難過!我對此有點新,任何幫助都非常感謝!

順便說一句我的索引頁路過網址item.php頁被改寫爲<a href="title/id">上我只是不能似乎得到它的正確格式爲mixtapes/title/id

當前htaccess文件位於「/混音帶/」執行item.php?title=a&id=b

# turn mod_rewrite engine on 
RewriteEngine On 

# rewrite all physical existing file or folder 
RewriteCond %{REQUEST_FILENAME} !-f [OR] 
RewriteCond %{REQUEST_FILENAME} !-d 

# allow things that are certainly necessary 
RewriteCond %{REQUEST_URI} "/css/" [OR] 
RewriteCond %{REQUEST_URI} "/images/" [OR] 
RewriteCond %{REQUEST_URI} "/images/" [OR] 
RewriteCond %{REQUEST_URI} "/javascript/" 

# rewrite rules 
RewriteRule ^mixtapes/item.php(.*) - [L] 
RewriteRule ^(.*) item.php?id=$1 [QSA] 

回答

0

在你的.htaccess的意見實際上說明錯誤

# turn mod_rewrite engine on 
RewriteEngine On 

# if requested URL is NOT a existing file 
RewriteCond %{REQUEST_FILENAME} !-f [OR] 
# or if requested URL is NOT a directory 
RewriteCond %{REQUEST_FILENAME} !-d 

# CSS, images, JavaScript are files and we will never pass this point when those are requested, next rules can be skipped 

# rewrite rules 
# rewrite /mixtapes/title/id to item.php?title=title&id=id 
Rewrite ^mixtapes/([^/]+)/([0-9]+) item.php?title=$1&id=$2 [L] 

# catch all other requests and handle them (optional, default would be 404 if not a physically existing file) 
Rewrite (.*) index.php [L,QSA] 

我假設你的id是一個數字值。 請注意在php中使用標題。不要直接輸出,但可以使用它來驗證您的URL並重定向錯誤的標題/ ID組合