0

Scenario:

I have a http://www.example.com/ and I want my new project to be accessed via http://www.example.com/new.

Here's what I tried:

DocumentRoot /var/www/html/old/public/

Alias /new "/var/www/html/old/new/public/" # -> I tried

The problem with this is it's only working on http://www.example.com/new but if I access another page like http://www.example.com/new/page1 it's looking for the routing in the old project.

.htaccess on document root

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Here's the Nginx version, unfortunately the server I'm working with is Apache so I need to convert this into Apache vhost

location ^~ /new {
    alias "/var/www/html/old/new/public/";

    if (!-e $request_filename) {
        rewrite ^/(.*) /new/index.php?$query_string last;
    }

    try_files $uri $uri/ /index.php?$query_string;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+?\.php)(/.*)?$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}
kdlcruz
  • 111

1 Answers1

1

From the manual of the Alias directive

Note that if you include a trailing / on the URL-path then the server will require a trailing / in order to expand the alias. That is, if you use

Alias "/icons/" "/usr/local/apache/icons/"

then the URL /icons will not be aliased, as it lacks that trailing / Likewise, if you omit the slash on the URL-path then you must also omit it from the file-path.

So you either have a trailing / to few or too many in your current setup...

Try either

Alias /new /var/www/html/old/new/public

or

Alias /new/ /var/www/html/old/new/public/
HBruijn
  • 80,330
  • 24
  • 138
  • 209
  • Didn't work. I tried both of them. :( – kdlcruz Dec 08 '15 at 09:22
  • Do your log files tell you anything then? And you don't have .htaccess files or absolute paths in your code either? – HBruijn Dec 08 '15 at 09:25
  • I don't think log files will help me with this one because my goal is to make sure when I access the /new/* the doc root should stay on the new project. But I do have .htaccess in the doc root. Please see updates in my question. – kdlcruz Dec 08 '15 at 09:31
  • You hint about the .htaccess solved my problem! Thank you! – kdlcruz Dec 08 '15 at 09:49