Question

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

Was it helpful?

Solution 4

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.

OTHER TIPS

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

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

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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top