user2409347
user2409347

Reputation: 21

Very simple .htaccess mod_rewrite configuration gives 404

Ok, I'm starting to think that the problem is me but... ¿What's wrong here?

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule testpage\.html http://www.google.com [R] #It works
RewriteRule ^mineral/([0-9]+)/?$ ver.php?id=$1 [NC,L] #It doesn't

I have a folder called "WebX" and this .htaccess inside it along with other files from the web. mod_rewrite is working ok according to phpinfo and everything is running on localhost. The most courious thing is that if I type localhost/WebX/testpage.html it redirects to Google but unfortunately for me if I type localhost/WebX/mineral/1 it gives me 404. ¿What happens?

Upvotes: 1

Views: 76

Answers (1)

Sumurai8
Sumurai8

Reputation: 20737

The problem you are having is caused by RewriteBase /. Your .htaccess is in a subdirectory /WebX/, but you are telling mod_rewrite to rewrite rules as if the current directory was /. It tries to load a file ver.php in your www-root, which doesn't exist. If you have verbose error messages with what file it tried to load, you'll notice it says that it tried to load /ver.php and not /WebX/ver.php as you might expect.

The rest you are doing, most notably using a relative url instead of a / prefixed absolute url, seems correct. The correct .htaccess to use would be:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /WebX/
RewriteRule testpage\.html http://www.google.com [R] #It works
RewriteRule ^mineral/([0-9]+)/?$ ver.php?id=$1 [NC,L] #It now should work

Upvotes: 1

Related Questions