Welcome to WebmasterWorld Guest from 34.229.24.100

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

mod_rewrite causing 403 Forbidden

mod_rewrite causing 403 Forbidden

     
4:46 pm on Sep 2, 2003 (gmt 0)

New User

10+ Year Member

joined:May 30, 2003
posts:22
votes: 0


Hi,

I have placed the following into my .htaccess file:

RewriteEngine on
RewriteRule ^fake\.html$ index.html [L]

It works fine on my local machine, but fails to work on the remote server.

I thought it was that mod_rewrite wasnt there, but phpinfo.php sugguests that mod_rewrite is one of the 'Loaded Modules'.

I am now a bit lost as to whose fault it is.
a) My .htaccess file and my understanding is incorrect
b) The server hasnt got mod_rewrite setup right
c) both
d) neither - something else

Thanks in advance

11:25 pm on Sept 2, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


cheethebee,

That should have worked. If you requested fake.html, your server should have responded with the contents of index.html in the same subdirectory. You might try it as an absolute path (with a slash) as shown.


RewriteEngine on
RewriteRule ^fake\.html$ /index.html [L]

Do you have access to a raw access or error log? Very often, these will point you to the problem. Often, you will see that the server path is different from the url path, and then you can use RewriteBase to correct misdirected requests. For example, you may need to add something like:

RewriteBase /usr/<site_name>/public/

to your .htaccess code, just after "RewriteEngine on". This is only an example, your path will surely be different.

Ref: Introduction to mod_rewrite [webmasterworld.com]

Jim

5:39 am on Sept 3, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:May 3, 2003
posts:159
votes: 0


RewriteEngine On
will have no effect in
.htaccess

Put it in your master server or virtual host config. This is a deliberate Apache limitation for security's sake.
6:10 am on Sept 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


StoryTeller,

If you have more detailed information about this, please post.

RewriteEngine is a supported directive in per-directory .htaccess context in Apache 1.3 and Apache 2.0 as stated in the Apache documentation, and it seems to work well on my sites - at least as long as Options FollowSymLinks are enabled as necessary.

I've surrounded "suspect" mod_rewrite code blocks with RewriteEngine off and RewriteEngine on directives to "turn off" the code blocks temporarily to see if a problem goes away. It works for me.

I'm therefore rather confused by your post. :o

Jim

6:31 am on Sept 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 21, 1999
posts:2141
votes: 0


cheethebee, try enabling symbolic links, some servers require it, depends on how the server is configured.


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^fake\.html$ /index.html [L]
6:47 am on Sept 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


The funny thing is, cheethebee's getting a 403-Forbidden, not a 500-Server Error, which is what you'd expect with a mod_rewrite configuration problem.

I'm wondering if another rewrite (possibly at the httpd.conf level) is preempting the intended rewrite such that a 403-Forbidden is the result. It's a stumper.

Jim

7:41 am on Sept 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
posts:881
votes: 0


snip: ignore me, user error, nothing to do with this topic.

Jordan

9:48 am on Sept 3, 2003 (gmt 0)

New User

10+ Year Member

joined:May 30, 2003
posts:22
votes: 0


Much thanks to both DaveAtIFG and JdMorgan.

The follow symlinks option proved to be the problem. And the base parameter will save me doing a lot of typing later on.

Cheers.

6:13 am on Sept 4, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:May 3, 2003
posts:159
votes: 0


jdMorgan, sorry, I wasn't 100% correct. Here's an excerpt from Apache documentation:

Note that, by default, rewrite configurations are not inherited. This means that you need to have a RewriteEngine on directive for each virtual host in which you wish to use it.

That said, RewriteEngine On can have effect in .htaccess, but only if it's in VirtualHost or server config already.

6:49 am on Sept 4, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:May 14, 2003
posts:376
votes: 0


storyteller,

i'm reading that as meaning that if you have some mod_rewrite rules in the main site configuration that they will not be inherited by the virtual hosts you may define... that you have to specifically set them in the virtual hosts via one of the allowed means (conf file or .htaccess or blah)...

in my experiance, the only thing related to mod_rewrite that i had to have in the master config was the module loading commands... after that and with proper OPTIONS, each site, master and virtuals, are on their own...

3:45 pm on Sept 4, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:May 3, 2003
posts:159
votes: 0


wkitty, I've recently had an experience with mod_rewrite not willing to work without RewriteEngine On in VirtualHost config. We tried to put it right in .htaccess, but there was no rewriting performed.

As to your reading of this - sure, that's what happens in practice, but I don't see how this can follow from this passage which tells about RewriteEngine ;)