-1

I am using a Virtual Host for my Laravel 4 Project on my local host to get rid off typing 'localhost/L4/public/index.php/route'. Laravel also uses a .htaccess file in it's public directory. Both the Virtual Host and .htaccess files are given below:

Virtual Host File

<VirtualHost *:80>
    ServerAdmin admin@mail.com
    DocumentRoot /var/www/L4/public

    ServerName www.L4.dev

    Alias /billing /var/www/L5/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /var/www/L4/public/>
        AllowOverride All
    </Directory>
</VirtualHost>

.htaccess File for Laravel 4 Project

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

    RewriteEngine On

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

Suppose Laravel 4 project has a route 'route1'. This Virtual Host file and .htaccess file let me allow to access my Laravel 4 project's 'route1' using "www.L4.dev/index.php/route1".

I added the following in my Virtual Host file to get rid off 'index.php' from the above given address:

<Directory /var/www/L4/public/>
    AllowOverride All
</Directory>

This works fine and now I can access the my 'route1' route of Laravel 4 project using 'www.L4.dev/route1'.

But notice I'm also using an Alias '/billing' in my Virtual Host file to access another project L5 (laravel 5 project).

Now suppose this Laravel 5 project has a route 'route2' and to access this route I've to type 'www.L4.dev/billing/index.php/route2'.

I also want to get rid off 'index.php' from here as well but don't know how to do so???

I'm sure that I've to do some thing with this Virtual Host file and with the .htaccess file in 'pbulic' directory of L5 but don't know what and how to do?

Note: There is no Virtual Host file for Laravel 5 project, just Alias is getting used to access it.

.htacess file in 'L5/Public/' Directory

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

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

Can some one pleas help me in this regard ????

Khuram
  • 101
  • 2
  • 11

1 Answers1

0

Change your main .htaccess like that and remove the other:

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

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Billing
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^/billing/(.*) /billing/index.php/$1 [L]

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

Or you can use this trick:

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

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(/billing/|)(.*) $1index.php$2 [L]
</IfModule>
Froggiz
  • 3,043
  • 1
  • 19
  • 30
  • I've added this before Front Controller, but then my Alias **/billing** doesn't work and treated as the **route** of **laravel 4 project**. i.e. `www.L4.dev/billing/route2' In the above URI, **/billing** is treated as **route** of Laravel 4.2 not as an Alias. – Khuram Dec 24 '15 at 11:45
  • You have to add the rules i wrote in .htaccess File for Laravel 4 Project and then remove L5/Public/ which is useless – Froggiz Dec 24 '15 at 11:50
  • this works only for the '/' route. Don't works with any other route except '/'. I mean to say that when I access **www.L4.dev/billing** it is same as **www.L4.dev/billing/index.php** this works. It's a good progress for me. But when I access the equallent of **www.L4.dev/billing/index.php/route2** which is **www.L4.dev/billing/route2**, it doesn't work and gives me the error ** The requested URL /billing/route2 was not found on this server.** – Khuram Dec 24 '15 at 12:19
  • what is the result of acces to www.L4.dev/billing/index.php/route2 ? – Froggiz Dec 24 '15 at 13:12
  • It works fine. but if I remove **index.php** and just use **www.L4.dev/billing/index.php/route2** it gives the error **The requested URL /billing/route2 was not found on this server.** – Khuram Dec 24 '15 at 13:16
  • I updated the answer – Froggiz Dec 24 '15 at 13:26
  • Same error **Not Found The requested URL /billing/route2 was not found on this server.** – Khuram Dec 24 '15 at 14:02