Apache alias not working correctly

25,851

Solution 1

I know this is a very old post but I thought this information I found on another StackExchange site might be of assistance.

When using an alias in your apache configuration you also need to use RewriteBase in your .htaccess file that's the same as the alias.

Alias /antoniocs/project "/home/antoniocs/www/project"
<Directory "/home/antoniocs/www/project">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

Requires that you include...

RewriteEngine On    
RewriteBase /antoniocs/project

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

I actually noticed it on a project because there was a rewrite going on with images/js/css and all my supplemental files were not loading.

Solution 2

It sounds like a rewrite is taking place in the wrong location. For example, the webserver is trying to find the URL /home/antoniocs/www/project/index.php instead of the local file by the same path. Perhaps check the Drupal installation itself? You can check what the server thinks by looking at the requests for redirection using something like curl:

curl -I http://localhost/antoniocs/project/category

See if code 301 or 302 is returned, and that may help narrow down the problem. E.g.:

$ curl -I http://www.outflux.net/blog
HTTP/1.1 301 Moved Permanently
...
Location: http://www.outflux.net/blog/

Solution 3

See if anything here can help: https://drupal.org/node/163915, your problem may have something to do with the AllowOverride statement in; /etc/apache2/sites-available/default

Solution 4

Alternatively you can also enable userdir module of apache. So that you don't have to create an alias to access the codes that resides in your home directory

sudo a2enmod userdir
cd ~
mkdir public_html
sudo /etc/init.d/apache2 restart

Put your code under this public_html and you can access it by http://localhost/~username or http://ipaddress/~username (for example: http://localhost/~aneesh)

You can change the directory name(public_html) by editing the conf file /etc/apache2/mods-enabled/userdir.conf

Share:
25,851
AntonioCS
Author by

AntonioCS

PHP/JS Programmer. Also dabble in Java and C/C++.

Updated on September 17, 2022

Comments

  • AntonioCS
    AntonioCS over 1 year

    I have added these lines in my 000-default virtual host file:

    Alias /antoniocs/project "/home/antoniocs/www/project"
    <Directory "/home/antoniocs/www/project">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    

    /home/antoniocs/www/project Contains a drupal website

    If I go to:

    localhost/antoniocs/project

    This works out fine. I see everything perfectly. But when I try to click on a link that takes me, for example, to:

    localhost/antoniocs/project/category

    I get this error:

    Not Found

    The requested URL /home/antoniocs/www/project/index.php was not found on this server.

    Is this not processing the .htaccess that is in the project folder? What am I doing wrong???

    NOTE: I also find it strange that it's giving me a file path and not an url path

    Running on Apache 2.2.16 (with mod rewrite) Ubuntu 10.10 php 5.3.3-1ubuntu9.1

    EXTRA NOTE: For those that don't know drupals htaccess, it redirects everything to index.php?q=$1

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{REQUEST_URI} !=/favicon.ico

    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

  • AntonioCS
    AntonioCS over 13 years
    The code returned is 404 :(
  • AntonioCS
    AntonioCS over 13 years
    Thanks for this tip. I edited the userdir.conf and changed public_html to www but apache does not seem to reload the module configurations. Do I need to disable and enable the module for the new configurations to take effect? Also I tried putting a php file in the public_html (just to test it) and it sent me the file instead of running the php file
  • AntonioCS
    AntonioCS over 13 years
    Ok I figured out what the problem was I forgot to change the UserDir. I keep having the same problem with clean urls, apparently the .htaccess is not being read
  • aneeshep
    aneeshep over 13 years
    i assume that you are running php. Just have a look at /etc/apache2/mods-enabled/php5.conf. and comment the following section if it is not already done. <IfModule mod_userdir.c> <Directory /home/*/public_html> php_admin_value engine Off </Directory> </IfModule> </IfModule>
  • Joe C
    Joe C over 7 years
    Thank you Vagari. You saved me. I was experiencing a similar issue with cakephp 3.0. I was stuck for a week on it. I had to add RewriteBase to my .htaccess file in my app directory and in my webroot directory. Thx again.
  • Adam
    Adam over 4 years
    This is the right answer.