Forum Moderators: phranque

Message Too Old, No Replies

mod_redirect 403 error

403 error occurs - mod_rewrite newbie

         

Markos101

1:10 pm on May 30, 2004 (gmt 0)

10+ Year Member



Dear All

I'm a newbie to mod_rewrite. All I want to do is use mod_rewrite to make all my php scripts referrable without the '.php' extension. So for instance if I put 'http://mydomain.com/index' into my address bar, I would get 'http://mydomain.com/index.php'.

I have been told that this should (in theory) do the trick:

<IfModule mod_rewrite.c>
Options FollowSymlinks
RewriteEngine On
RewriteRule index* index.php [R]
</IfModule>

However, when I use this script, all URLs directed towards my site then give a 403 error (permissions). If I comment out 'RewriteEngine On', it works normally. Can anyone help? No one seems to be able to shed any light on this problem. I've tried it with and without [R].

If I do put 'http://mydomain.com/index', it does indeed redirect to index.php, however it still gives the 403 error.

Cheers
Mark

gergoe

1:30 pm on May 30, 2004 (gmt 0)

10+ Year Member



Try

Options FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^index index.php [T=application/x-httpd-php]

If this is not in a htaccess file in your root directory, then you'll need to adjust the RewriteBase according in which directory you've placed this.

Markos101

1:58 pm on May 30, 2004 (gmt 0)

10+ Year Member



Hi gergoe

Thanks very much for your response.

It doesn't seem to be working - it still gives me the 403 error. My .htaccess file is the root directory of my HTML folder.

gergoe

3:29 pm on May 30, 2004 (gmt 0)

10+ Year Member



It could be because of a loop, if you add a RewriteCond just before the RewriteRule to leave the url unchanged if the request is for the index.php then it might solve the problem. Something like this:

RewriteCond %{REQUEST_URI} !^index\.php

See the mod_rewrite documentation [httpd.apache.org] and some resources/tutorials about Regular Expressions available on the internet.