views:

153

answers:

4

In the httpd.conf file I have AllowOverride FileInfo. In the .htaccess file in top level of my webserver with all the other files, I have this:

RewriteEngine On
RewriteRule ^downloads/?$ index.php?page=downloads [L,NC]

But it doesn't work. mywebsite/downloads and mywebsite/downloads/ always give a 404 not found. Any idea why? Thanks. (mywebsite/index.php?page=downloads does work).

And I'm restarting apache every time I change it.

And when I put the code above in httpd.conf, the website won't even load at all, just blank, spinning safari wheel forever.

Its fine if I just do RewriteEngine On, but if I do anything else (RewriteBase, RewriteRule), the web browser spend ages trying to load and finally giving this error:

Safari can’t open the page “http://mk12.gotdns.com/” because the server where this page is located isn’t responding.

Anyone have any idea what's wrong?

EDIT: I'm able to make, for example, css files forbidden with rewrite, and it works, but any rule that goes from downloads to index.php?page=downloads makes the server not respond (see above), it doesn't matter what page, the website won't load at all. Any ideas..?

A: 

Have you tired adding a slash in front of the "download" like below

RewriteRule ^/downloads/?$ index.php?page=downloads

EDIT: Try the code below:

RewriteEngine On
RewriteBase /
RewriteRule ^downloads/?$ /index.php?page=downloads
BYK
It didn't work.
Mk12
Try removing the "^/" part completely(just for testing of course). If it does work, then you might have to set your base path to "/".
BYK
I already tried that.
Mk12
+1  A: 

The best way to debug rewrite rules is to enable rewrite logging so you can see what's going wrong.

Azeem.Butt
In the /private/var/log/apache2/error_log file, I get this: `[Sat Oct 24 16:42:05 2009] [error] [client 10.0.1.1] File does not exist: /Library/WebServer/Documents/downloads`.
Mk12
This means your pattern is not matched.
BYK
A: 

I would try removing the trailing slash and question mark after downloads, and the leading slash before index.php.

RewriteEngine On
RewriteBase /
RewriteRule ^downloads$ index.php?page=downloads.
TallGreenTree
I assume the period at the end is a typo?
Mk12
And still not working.
Mk12
A: 

It Worked!! I was putting the code in the wrong spot. It was in httpd.conf, but at the end. Move it into <Directory> and its good. Thanks for your help!

EDIT: Also, I found that It won't work if the flags are like this: [L, NC]. It has to be [L,NC] (no spaces).

So the two problems where that it wasn't inside <Directory "/Library/WebServer/Documents">, and there were spaces between the flags. Hopefully this will help someone else in the future.

Mk12