Forum Moderators: phranque

Message Too Old, No Replies

/private/ redirects to root index.php

Seems so simple but can't get it right

         

neophyte

3:34 am on Jul 18, 2010 (gmt 0)

10+ Year Member



Hello All -

Made a similar post a few weeks ago and got a clue from one member but after much study still can't get it working correctly (atleast I'm not getting 500 errors anymore!).

All that I'm trying to do is this:

Address bar reads: www.site.com/private/

The /private/ directory doesn't exist so I just want to make sure that when www.site.com/private/ is requested www.site.com/index.php is actually served.

I've got the following in my htaccess file on my local dev environment:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^private/$ index.php

But when I test it, I always get: The requested URL /testing/dev/index.php was not found on this server.

I guess it's some kind of regexp syntax problem relating to ^private/$ but I can't track it down. Can anyone help?

Neophyte

jdMorgan

4:02 am on Jul 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where, in the filesystem of your server, does /index.php exist?

The error message states that it is looking for /testing/dev/index.php.
If the file is not there, then where is it?

One of the more likely problems if this filepath is wrong is that the DocumentRoot for www.site.com is incorrectly defined.

Jim

neophyte

5:33 am on Jul 18, 2010 (gmt 0)

10+ Year Member



Hi JD -

My DocumentRoot is "C:/Apache2.2/htdocs" which is correct - however, I've aliased all of my projects to a different directory on a different HD.

I've never had any problem with my DocumentRoot settings before unless the Aliasing is causing an issue with mod_rewrite (could that be it?)

I can confirm that index.php is indeed within /testing/dev/ - more explicitly: E:/testing/dev/index.php.

Other than this issue, is my RewriteRule correct?

Would be grateful for any additional guidance if possible.

neophyte

5:38 am on Jul 18, 2010 (gmt 0)

10+ Year Member



Another thing -

When doing some simple testing (when I was trying to get use to the whole RewriteRule concept, I tested this:

#RewriteRule ^index.php$ index.php?cmd=02.03.00

which worked perfectly - index is called, which then loads the page designated by "cmd-02.03.00".

So, if that works, I'm wondering why I'm getting this error with RewriteRule ^private/$ index.php?

jdMorgan

7:15 pm on Jul 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code is essentially correct, although the [L] flag is missing and the Options can be combined on one line. I usually suggest
 Options +FollowSymLinks -Indexes -MultiViews 

unless you really do use automatic directory file listings and content-negotiation.

Understand that DocumentRoot is applied to all requests, so your server may be looking for your script at C:/Apache2.2/htdocs/testing/dev/index.php

Alias directives may be applied before or after mod_rewrite directives -- test to find out which.

Jim

neophyte

1:02 am on Jul 19, 2010 (gmt 0)

10+ Year Member



Hi JD -

Thanks for your continued guidance. Here's what I've done so far (unfortunately still no luck regarding "private/"):

htaccess:
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteRule ^private/$ index.php [L]

httpd.conf:
Alias /sangat "E:/Sangat/Development"

Testing URL in address bar:
"http://localhost/sangat/private/"

Browser error (404):
The requested URL /Sangat/Development/index.php was not found on this server.

I don't know if my Alias is being triggered before or after mod_rewrite and don't know how to test for that - Should I put the Alias line somewhere inside the htaccess?

What continues to baffle me is that if I change the rewrite rule to RewriteRule ^index.php$ index.php?cmd=02.03.00 [L] (as a test) then everything works like a charm.

I'm obviously a newbie when it comes to all of this - and do appreciate your continued advice. Is there anything else you can suggest to I can get this working?

Neophyte

neophyte

2:02 am on Jul 19, 2010 (gmt 0)

10+ Year Member



JD -

Forgot to add in my last post that in my httpd.conf file, I've also have the following set:

<Directory "E:/Sangat/Development">
Options +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

Maybe since I've got Options +FollowSymLinks set both in this file AND htaccess this is screwing it up?

jdMorgan

4:06 am on Jul 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your alias is being applied before your mod_rewrite code can execute. Move the code to the directory on the "E" drive, and it should work.

Or get rid of the Alias completely, and replace its function with two rewriterules -- one to handle the '/private' case, and the other rule to handle all other cases... in that order.

Jim

neophyte

11:49 pm on Jul 19, 2010 (gmt 0)

10+ Year Member



Hello JD -

I don't want to be overly-dense, but when you say to "Move the code to the directory on the "E" drive, and it should work" which code are you talking about? and when you say move it to "E" drive, you mean put the code you're talking about in my htaccess file in the root of the site - which is on "E"?

Sorry about these apparently bone-head questions.

Neophyte

jdMorgan

5:31 pm on Jul 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, put the .htaccess code into the physical directory where it is to be applied.

Jim