-1

I would like to know how to configure Apache to do the following:

Configuration 1

When a user points their browser to http://localhost/ (and gets the contents of /var/www/index.html) the browser redirects to http://localhost/magento/ (and gets the contents of /var/www/magento/index.php)

Configuration 2

  1. When the user enters the URL http://localhost/magento/ the contents of the directory /var/www/magento/index.php are displayed but the URL changes to http://localhost/

  2. Conversely when the user enteres http://localhost/ in their browser the URL does not change but the contents of /var/www/magento/ are displayed.

  3. http://localhost/foo/bar/foobar/ and all URLS of this sort display the contants of /var/www/magento/foo/bar/foobar instead of those of /var/www/foo/bar/foobar


I have tried defining a file called /var/www/.htaccess, which I am sure is getting parsed by apache2, but I don't see any of the above happen. What I've placed in it is:

RewriteRule / /magento/
1
  • The three things you've asked for are mutually exclusive. What is it that you really are trying to do? Commented Jul 29, 2012 at 15:21

1 Answer 1

1

Make sure that you have these lines uncommented in your http.conf (they come commented out by default):

#LoadModule rewrite_module modules/mod_rewrite.so

This may be present for different versions of apache, uncomment if you have it.

#AddModule mod_rewrite.c


That should get the rewrite engine turned on. Now for your rules:

In your .htaccess file (that is in your website root directory) add this line at the top:

RewriteEngine on

Now with that setup you should be turned on and enabled. Now just fire off some rules. In your case I think that should look like:

RewriteRule ^/magento$ / 


Take a look at http://www.sitepoint.com/guide-url-rewriting-2/ for an easy to follow tutorial.


EDIT
Make sure to check that you allow overrides from your .htaccess files. Find the <directory /> section in your httpd.conf and modify as follows:

<Directory />    
     Options FollowSymLinks    
     AllowOverride All
#    Order deny,allow
#    Deny from all
</Directory>


Here's a good post that explains common problems with enabling mod_rewrite: http://book.cakephp.org/1.3/view/917/Apache-and-mod_rewrite-and-htaccess

2
  • Hello, I've tried your solution, I've got rewrite.load inside /etc/apache2/mods-enabled, but when I place the .htaccess file in the root directory and move index.html and index.php to something other than index.html.bak and index.php.bak so that apache doesn't try to open them, I just get a directory lising of the server root, no redirection. And when I go to http: //localhost/magento I don't see the rewrite I was asking about. Commented Jul 29, 2012 at 18:20
  • See the edit for more stuff to check.
    – barancw
    Commented Jul 29, 2012 at 23:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .