views:

44

answers:

2

Hello,

I have a problem with my two RewriteRules.

.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]

If the url contains download (some like this: mydomain.com/download/9) the first rule should redict this request to download.php?id=9. But it doesn't.

var_dump($_GET) shows the following:

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

Any ideas?

A: 

The problem is not with the rule. It works here.

http://wingsoflol.org/download/9

My download.php contains

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

and the rule is

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

Are you sure the RewriteBase should be /test/ ?

Christian Jonassen
Yes. I'm working at localhost and the folder test:http://localhost/test/download/9But add the second rule and try again.
daniel
Works perfectly here. Try adding the prefix test/ to the rules and see if this is the problem. For fun, I added the RewriteBase rule, and it does not work here. Read http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritebase
Christian Jonassen
Also read http://stackoverflow.com/questions/704102/how-does-rewritebase-work-in-htaccess
Christian Jonassen
A: 

Ok, I solved the problem.

# 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]

Thanks guys! :)

daniel