1

I'm trying to make a dynamic developing environment with virtual host. Now i have:

<VirtualHost *:80>
   UseCanonicalName Off
   VirtualDocumentRoot "C:\xampp\htdocs\%1\public"
   # available aliases to use
   ServerAlias *.dev
</VirtualHost>

And it works for the default route of Laravel:

Route::get('/', function () {
    return view('home.index');
});

But any other route will give me a 500 error of to many internal redirects. I use Laravel 5.2 without any changes at all except for the routes.php and some default changes.

When I assign the domain like this as VirtualHost it works all just fine:

<VirtualHost *:80>
  ServerName example.dev
  VirtualDocumentRoot none
  DocumentRoot "C:\xampp\htdocs\example\public"
</VirtualHost>

How can I fix this problem so I can use dynamic domain names so I don't have to add all domains manually.

Thank you in advance, Stefan Fransen

Edit

When I use this:

http://example.dev/index.php/test

The page is loading correctly but this is not what I want. So how do i remove the index.php from the url? i've checked and al modules are loaded correctly this is my .htaccess:

<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]

#    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

Edit

Found out that when I changed RewriteRule ^ index.php [L] to RewriteRule ^(.*)$ /index.php/$1 [L]

But I still don't understand why it does work on a manual added vhost but not on a dynamically generated vhost, does someone have a explanation for that?

  • check this guide line i use it for laravel http://stackoverflow.com/questions/27754367/how-to-setting-virtual-hosts-for-xampp-in-windows/27754990#27754990 – Maytham Fahmi Apr 20 '16 at 22:02
  • Thanks for your comment but you're using VirtualHost by adding each single "project" to the vhost. That part did work on my end but I don't like to add them manually cause there will be to many to add. So instead I want each directory for example "example" to refer to "example.dev" this part is not working jet – Stefan Fransen Apr 21 '16 at 13:43

2 Answers2

0

I guess you rewrite module (mod_rewrite) is disabled. Check it in apache.conf

Maybe section Pretty URLs can help you. https://laravel.com/docs/5.1

0

I got the same problem. I found a solution for it.

Go to .htaccess file on root directory if it is not in root directory then it will be available in public folder cut from there and paste into the root directory

Change the following code.

RewriteRule ^ index.php [L]

to

RewriteRule ^(.*)$ /index.php/$1 [L]

Sumit Kumar Gupta
  • 2,132
  • 1
  • 22
  • 21