2010-05-24 82 views
1

我有我的兩個RewriteRules的問題。問題.htaccess(mod_rewrite)。重寫規則的doens't正常工作

的.htaccess:

# protect the htaccess file 
<files .htaccess> 
order allow,deny 
deny from all 
</files> 

RewriteEngine On 
Options +FollowSymlinks 
Options -Indexes 
RewriteBase /test/ 

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

RewriteRule ^download/([0-9]+)$ download.php?id=$1 [L] 
RewriteRule ^(.*)$ index.php?c=view&misc=$1 [B] 

如果URL包含下載(一些這樣的:mydomain.com/download/9)的第一條規則應該redict這個請求的download.php ID = 9?。但事實並非如此。

的var_dump($ _ GET)顯示如下:

array(2) { ["c"]=> string(4) "view" ["misc"]=> string(9) "index.php" } index.php 

任何想法?

回答

1

好的,我解決了這個問題。

# protect the htaccess file 
<files .htaccess> 
order allow,deny 
deny from all 
</files> 

RewriteEngine On 
Options +FollowSymlinks 
Options -Indexes 

RewriteBase /test/download/ 
RewriteRule ^download/([0-9]+)$ download.php?id=$1 [L] 

RewriteBase /test/ 

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

RewriteRule ^(.*)$ index.php?c=view&misc=$1 [B] 

謝謝你們! :)

0

問題不在於規則。它在這裏工作。

http://wingsoflol.org/download/9

我的download.php包含

Hi! 
<br>Id = <? 
echo $_GET['id']; 
?> 

和規則是

RewriteRule ^download/([0-9]+)$ download.php?id=$1 [L]

你確定RewriteBase應該是/測試/?

+0

是的。我正在本地主機和文件夾測試: http:// localhost/test/download/9 但添加第二個規則,然後再試一次。 – daniel 2010-05-24 11:32:29

+0

在這裏完美的作品。嘗試將前綴test /添加到規則中,看看這是否是問題。爲了好玩,我添加了RewriteBase規則,並且在這裏不起作用。閱讀http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritebase – 2010-05-24 13:44:23

+0

同時閱讀http://stackoverflow.com/questions/704102/how-does-rewritebase-work-in-htaccess – 2010-05-24 13:46:46