2013-08-17 53 views
1

我試圖寫一個htaccess文件,我無法正常工作。我的網站上有一個名爲「gpio」的目錄。我正在編寫的htaccess文件位於/ var/www/gpio中。.htaccess重寫規則不會追加查詢字符串的路徑

當有人請求URL http://domain.com/gpio時,我希望將請求重定向到腳本,'gpio'附加到查詢字符串中。這是我有我的htaccess文件:

# .htaccess 
#DirectoryIndex index.html 
RewriteEngine on 

# I changed domain name a few months ago... 
RewriteCond %{HTTP_HOST} ^olddomain.com/*$ 
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L] 

# handle the case where the directory exists 
RewriteCond %{REQUEST_FILENAME} -d 
# this is the part that doesn't work 
RewriteRule ^(.*)$ /cgi-bin/pyindex.cgi?q=$1 [L,QSA] 

# handle the case where a file is requested 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ /cgi-bin/pyindex.cgi?q=$1 [L,QSA] 

的問題是,當我訪問這個URL,我重定向到腳本,但請求的路徑不會被追加到查詢字符串。在pyindex.cgi中,當查詢字符串被打印時,它只包含'q ='。最終的結果是,當我看到代表帖子類別的頁面時,我正在看到我的主頁。

任何想什麼我做錯了,將不勝感激。

回答

1

要麼有規則內/var/www/.htaccess或修改它

RewriteRule ^$ /cgi-bin/pyindex.cgi?q=gpio [L,QSA] 
RewriteRule ^(.+)/?$ /cgi-bin/pyindex.cgi?q=gpio/$1 [L,QSA] 

而且,以下規則測試,如果請求文件(並因此將匹配目錄以及)

RewriteCond %{REQUEST_FILENAME} !-f # remove ! to match files 
+0

謝謝拉維。我把代碼放在/var/www/.htaccess中,解決了這個問題。 – Steve

相關問題