1

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?

Gumbo
  • 643,351
  • 109
  • 780
  • 844
daniel
  • 207
  • 2
  • 9

2 Answers2

1

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
  • 207
  • 2
  • 9
0

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 Neverdal
  • 5,655
  • 6
  • 38
  • 93
  • Yes. I'm working at localhost and the folder test: http://localhost/test/download/9 But add the second rule and try again. – daniel May 24 '10 at 11:32
  • 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 Neverdal May 24 '10 at 13:44
  • Also read http://stackoverflow.com/questions/704102/how-does-rewritebase-work-in-htaccess – Christian Neverdal May 24 '10 at 13:46