Htaccess and vhosts

I have an app that I am doing locally using a vhost account so the local address is “http://myapp/”. The htaccess file doesn’t seem to be recognized when using a RewriteRule to redirect a page.


RewriteRule ^My_Account/?$ /mydir/index.php?%1 [L,QSA]

When I use the remote site with the same htaccess file it works fine. It addresses to “http://www.myapp.com/”.

Is there a reason for this or do I have some other problem? The error I am getting is “The requested URL /My_Account was not found on this server.”

Is this an issue of addressing? I have another local app that I use that is using localhost as it’s root that uses this same base addressing and it works fine. The root for the vhost is obviously different as c:\vhosts\myapp\mydir\index.php, do I need to qualify the address somehow?

Thanks

I assume you have Options +SymLinks in the .htaccess (or have it enabled in the httpd.conf) and RewriteEngine On in the .htaccess?

If so, is /mydir/ a subdirectory of the document root, and does the file index.php exist? (I assume yes, but I don’t quite get what you said about the document root, which is why I ask).

Here is what precedes the ReWrite rule

AddHandler php5-script .php

Options +FollowSymLinks -Indexes

RewriteEngine On


And yes, I am using vhosts on a local drive so the path is c:\vhosts\myapp\mydir\index.php.

And yes, there is an index.php.

Looks okay. There are two more things I imagine are wrong now

  1. Your localhost is running Apache 1.x. Change “^My_Account/?$” in the rule to "^/?My_Account/?$ to see if that works. (if it does you are indeed on Apache 1.x)

  2. Your apache config doesn’t allow (or read) .htaccess files. Put this is the httpd.conf


<Directory c:\\vhosts\\myapp\\>
   AllowOverride All
</Directory>

If both solutions don’t work enable the RewriteLog to see if that shows you anything.

I’m lost on this now. The directory structure is

/var/www/vhosts/myapp1/httpdocs/

where httpdocs is the root directory for the site. The apache and php config files are under the /etc/ directory which is on the same level as /var/ which I assume means the different apps (myapp1, myapp2) share the same php and apache configuration files. Is that how that works? I don’t want both apps to use the same htaccess files or the same session variables. Currently with no specific configuration in the httpd.conf file for myapp1, it is working fine but myapp2 is not recognizing the htaccess ReWrite rules. Does any of that make sense?

I think I will post the php.ini part of this on the php site because I believe that is the problem I am having with session variables.

RewriteRules not working has got nothing to do with php, since php only kicks in after Apache has done it’s part in rewriting, etc

And indeed, there is (normally) only one apache and php install, and every project running on it uses the same configuration. It is however possible in the httpd.conf to change certain options on a per-directory basis, so it is very much possible that an .htaccess works in one dir but not in another like you said.

I’m confuses now however as what works and what doesn’t. Do the rewriterules work on your localhost? Do they work on the live host?
On which host (local or live) does the other project that works “live” ?

I started with 2 environments, one on localhost on my computer for mayapp1 and one on the remote server for myapp1. Both work fine for quite a few ReWrite rules, approx 50. Now I have installed myapp2 on both the localhost and on the remote server. On localhost, myapp1 is in htdocs but myapp2 is in a vhosts directory. On the remote server, both are under the vhosts directory. ReWrite rules doesn’t work in either environment for myapp2.

I just looked in the localhost version of httpd.conf and there were entries for some other vhosts accounts (not myapp1) so I put one in for myapp2. Prior to putting it in, ReWrite rules didn’t work, now it does so that definitely fixed that. There is also 1 in there for c:\htdocs which is why myapp1 works so I understand all that.


<Directory "C:/vhosts/stblocal">
    Options Indexes FollowSymLinks
    AllowOverride ALL
    Order allow,deny
    Allow from all
</Directory>

Now let me do the same for the remote app and will report back. And yes, I realize this is what you said to do before, I suppose I just didn’t understand and it was late and I was in the programmer tunnel. :slight_smile:

One side question, are there any issues with now many ReWrite rules you can have? I currently have about 50 for myapp1 as I use them for URL presentation so they are all clean without ? notation.

Excellent, I added blocks for myapp1 and myapp2 on the remote server. myapp1 still works and myapp2 works also. Thanks so much for your help. Now I can move on and definitely going to take the time to document this for future reference. :slight_smile: