Apache virtual host always redirecting to /dashboard - php

I'm having what appears to be a common problem but any solutions I've found don't seem to work for my case.
I'm trying to set up a virtual host so that I can access the public file of my Laravel installation by going to "mytestdomain.local" but when I type this address into google chrome I am always redirected to the xampp dashboard at this address "https://mytestdomain.local/dashboard/".
I've installed Laravel in the following xampp directory: c:/xampp/htdocs/mytestdomain_uk.
I have "C:\xampp\apache\conf\extra\httpd-vhosts.conf" set up as follows:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/mytestdomain_uk/public"
ServerName mytestdomain.local
</VirtualHost>
And I have "C:\Windows\System32\drivers\etc\hosts" set up as follows:
127.0.0.1 localhost
127.0.0.1 mytestdomain.local
If anyone could offer any insight into this issue I would be very grateful.

Put this as the first line in C:\...\httpd-vhosts.conf (and restart the web server):
NameVirtualHost *:80
So, it should look like this:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>
<VirtualHost *:80>
ServerName walkpeakdistrict.local
DocumentRoot "C:/xampp/htdocs/walkpeakdistrict_uk/public"
</VirtualHost>
I would place all my projects somewhere outside of C:/xampp/htdocs and C:/xampp. Let C:/xampp/htdocs be the standard localhost location, with just two files inside (simple index.php and index.html), but use another one for the projects. Even better, use another partition, not the system partition C:. Like D:/projects, or so. So, you would have D:/projects/walkpeakdistrict_uk.
Good luck.

Ok, I'm not sure why this was an issue but it seems to work when I change the virtual host's server name to anything other than ".local".
Thanks again to all who replied!

This happened with me as well. And I resolved it. In my case, it was happening because of the SSL module. So, turning it off got me out of the trouble. Just Open the httpd.conf file and comment the SSL include code by adding # to the front of the code as given below.
# Secure (SSL/TLS) connections
# Include conf/extra/httpd-ssl.conf
After this, it will be resolved.

I'm pretty sure the issue for me had to do with SSL redirects, for some reason. When I edited my .htaccess to exclude local.mydomain.com when forcing https, I stopped getting redirected to the XAMPP dashboard.
Below is the section of my .htaccess that excludes local sites from redirecting to https. You can add extra RewriteCond lines for other local domains.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTP_HOST} !local\.
RewriteCond %{HTTP_HOST} !other.localdomain.example.com
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
</IfModule>
<IfModule mod_headers.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !local\.
RewriteCond %{HTTP_HOST} !other.localdomain.example.com
Header set Strict-Transport-Security "max-age=16070400" env=HTTPS
</IfModule>

Change your document root to this, just add a slash at the end of public and it will work
DocumentRoot "C:/xampp/htdocs/walkpeakdistrict_uk/public/"

I had this problem after developing my website and I got round it by simply rebooting my machine. Many months later, Google then invalidated the use of .dev so my virtual host stopped working. I changed the name of my virtual host to .test and got the dashboard. I had forgotten the simple solution and arrived on this page searching for a solution. Then i remembered......I rebooted my machine and hey presto....it worked. No more dashboard. I get the right homepage.

In your case, you put localhost settings in virtual host. check if you got this script on default file conf, then comment it. Case on xampp for mac
Include "${your_xampp_path}/conf/httpd.conf"

The solution is very simple, it always redirects the https url to the Dasboard, you just have to remove the s leaving http:
Example:
http://juego123.com

I was facing the same error. I solved the error by removing the *80 port number from the virtual host tag and then my code look like
<VirtualHost *>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>
<VirtualHost *>
ServerName walkpeakdistrict.local
DocumentRoot "C:/xampp/htdocs/walkpeakdistrict_uk/public"
</VirtualHost>
**NOTE:**Your Virtual Host tag looks like this <VirtualHost *>
This means we are redirecting to any other port or not bounding the virtual host to port 80 this will work definitely.

I came here with the same problem, in my case accessing the website through http instead https worked.
In browser, instead of accessing this way:
https://mytestdomain.loc
try this one
http://mytestdomain.loc

Its works for me once I remove header location from 'htdocs/index.php' file

Related

How to perfectly set up virtual host for codeigniter project?

I am trying to make a virtual host for a codeigniter project. I have done this in httpd-vhosts.conf:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\CI_projects\facebook-login"
ServerName dev.facebook-login.com
<Directory "C:\xampp\htdocs\CI_projects\facebook-login">
Require all granted
</Directory>
</VirtualHost>
and in application/config/config.php,
$config['base_url'] = 'http://dev.facebook-login.com';
and
$config['index_page'] = '';
the browser opens the landing page. but when transiting from any other uri it says object not found.
And when i configure httpd-vhosts.conf like this:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\CI_projects\facebook-login\index.php"
ServerName dev.facebook-login.com
<Directory "C:\xampp\htdocs\CI_projects\facebook-login\index.php">
Require all granted
</Directory>
</VirtualHost>
It arises problem with assets things, i,e images and some css doesnt loads. How can I solve it?
I am on windows 10 and I use xampp with virtual host this is way I set up.
Put forward slash at end of base url
$config['base_url'] = 'http://dev.facebook-login.com/';
First go to
Windows > System32 > drivers > etc > host
You may need to open as administrator to be able to save it
You might see some thing like
127.0.0.1 localhost
Below that create another one for dev.facebook-login.com like example:
127.0.0.1 localhost
127.0.0.1 dev.facebook-login.com
Save it
Then go to the
xampp > apache > conf > extra > httpd-vhosts.conf
open it as administrator so you can save it.
No need for the index.php on DocumentRoot
<VirtualHost *:80>
##ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "C:/xampp/htdocs/CI_projects/facebook-login"
ServerName dev.facebook-login.com
##ServerAlias www.dummy-host.example.com
##ErrorLog "logs/dummy-host.example.com-error.log"
##CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
Save it and restart the severs.
I use this for my htaccess
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
httpd-vhosts.conf
Listen 1122
<VirtualHost *:1122>
DocumentRoot "D:\laragon_server\www\hugpong_production"
<Directory "D:\laragon_server\www\hugpong_production">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
https://www.namecheap.com/support/knowledgebase/article.aspx/10026/33/installing-an-ssl-certificate-on-xampp/
php 8 is not ready for CI4 as of jan 2021!
XAMPP has preloaded ssl certificate in php 7 packages
consider uncommon vhosts extra and place this in it
my only persistent issues is codeigniter 4 routes, have to turn on php spark serve to get XAMPP to route pages outside of default index, nothing else works, its garbage to that extent, will try with composer next....a whole book needs
to be wrote about codeigniter 4 routes and why they don't work, 200 pages plus
<VirtualHost localhost *:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
<VirtualHost example.com *:8080>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "C:\xampp\htdocs\codeignite4\public"
//my project folder is codeignite4 without using composer this time
//i added listen 8080 under listen 80 in htppd.conf
ServerName example.com
<VirtualHost truservex.com *:443>
DocumentRoot "C:\xampp\htdocs\codeignite4\public"
ServerName example.com
SSLEngine On
SSLCertificateFile "C:/xampp/apache/conf/ssl.crt/server.crt"
// you can verifiy these file locations, certificate data
SSLCertificateKeyFile "C:/xampp/apache/conf/ssl.key/server.key"
// going without the Directory tag can be helpful to drop in vhosts
<Directory "C:\xampp\htdocs\codeignite4\public">
Require all granted
doing this i was able to replicate the original install, create site access
using http://localhost:8080 or http://example.com/ as my base url
in my example index.php is removed, set to ''
when using command prompt to get into codeignite4 project folder i can
launch php spark serve and routes will work that were previously 404
Using Xampp 7.3.25 Dec 2020 because php 8 will not run error
free with codeigniter 4 as of this date, this worked for me as
my first codeigniter 4 virtual host setup, my install had
difficulty initially with using port 80, seems to want to for
port 443 if it can..I'm not a server pro but i wanted to
leave this for the next guy....This is strictly name based
virtual hosts for develop, ip based would have obvious
advantages. Because i had trouble in initial CI4 testing with
port 80 the (*) in virtual hosts vs (*:80) seemed to solve one
hurdle in searching for more ports, now i can finally begin my
first project ...my default URL was also changed to example.com
in appstarter/apps/config file. Carefully reread <tags> for
typos, its easy to shut server down!
<VirtualHost *>
DocumentRoot "C:/Xampp/htdocs/"
ServerName localhost
<Directory "C:/Xampp/htdocs/">
Require all granted
<VirtualHost *>
DocumentRoot "C:/Xampp/htdocs/appstarter/public/"
ServerName example.com
ServerAlias www.example.com
# maybe don't attempt to use dir tag, shuts down server
# the directives at httpd.conf appear to suffice
I have added a htaccess file in the appstarter/public
I assume this is primitive, can get far more advanced
The Apache help pages helped me focus a bit more on
what i must accomplish, name based virtual hosts this case
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
2.2 Apache configuration: :Apache server context important!
Order allow,deny :The hackers are winning.....
Allow from all
2.4 Apache configuration:
Require all granted

Configuration of laravel under apache to avoid public

I recently installed laravel under a LAMP server, but can't get it to work if I don't specify public in the url for another routes than the index.php.
This is my apache site config (/etc/apache2/sites-available/furbook.com.conf):
<VirtualHost *:80>
ServerName furbook.calhost.com
DocumentRoot "/var/www/html/furbook.com/public"
<Directory "/var/www/html/furbook.com/public">
AllowOverride all
</Directory>
</VirtualHost>
Then created a symbolic link from /etc/apache2/sites-enabled:
sudo ln -s ../sites-available/furbook.com.conf
Finally, this is my .htaccess file in furbook/public:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
With this now I'm able to skip the public folder, localhost/furbook.com works redirecting to the public/index.php as expected.
But the problem is when I try to route an url like localhost/furbook.com/cats, then it throws a page not found error.
If I use localhost/furbook.com/public/catsthen works as expected.
What am I missing?
There's not quite enough information to answer you question 100% authoritatively -- here's my best guess.
If I use localhost/furbook.com/public/catsthen works as expected
Apache allows you to setup multiple "VirtualHost" configurations on a single server. A "VirtualHost" is a domain name like furbook.calhost.com that points to a specific folder on your computer. It's called Virtual because, at the time Apache was created, there was a strong bias towards "one host name/one physical server"
<VirtualHost *:80>
ServerName furbook.calhost.com
DocumentRoot "/var/www/html/furbook.com/public"
<Directory "/var/www/html/furbook.com/public">
AllowOverride all
</Directory>
</VirtualHost>
You have setup a virtual host for the name furbook.calhost.com
ServerName furbook.calhost.com
However, in your URL, you're still accessing the system via the name localhost. Accessing via localhost means apache will use the default host/site configuration, which (appears to) still be pointing at the folder above root.
Your options
Setup local DNS or a host file to have furbook.calhost.com point to 127.0.0.1
Change the default configuration of your apache system (probably in httpd.conf) to point to the public folder
Good luck!
(Also, don't forget Apache systems typically require a reset to pickup new configuration changes)

Silent redirect based on domain

I've set up my own server.
Let's say my main server folder is /home/www and I've set the nameservers so that all domains point to this location.
Now, here's what I want to do :
Have each domain's files in a separate subfolder
Based on the domain requested, silently redirect to the appropriate subfolder
E.g.
if we need somedomain.com or www.somedomain.com or www.somedomain.com/anything/ (or any such variation for that matter) redirect the request from /home/www/ to /home/www/somedomain.com/
How can this be done?
And here's what I've tried (but given that .htaccess is definitely ... not my thing, it'll most likely be close to non-sensical...) :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?somedomain.com$ [NC]
RewriteRule ^(/)?$ somedomain.com [L]
There are two possible choices. you can create Virtual Host for each domain and set virtual document root.
Or
You can use rewrite rule.
From apache Virtual host documentation:
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/www.example1.com
ServerName www.example1.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/www.example2.org
ServerName www.example2.org
# Other directives here
</VirtualHost>
You can find out more in http://httpd.apache.org/docs/2.2/vhosts/examples.html

Laravel 4 Virtual Host and mod rewrite setup

I've been trying for a few hours to install Laravel 4 and make the Virtual Hosts and Routing work but so far I've been unlucky. I'm mentioning that I'm doing this on a Windows 7 machine and WAMP.
I'll describe what I've already done:
I've enabled rewrite_module.
Updated httpd-vhosts.conf with the following:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
</VirtualHost>
Next, I've set up the etc/hosts:
127.0.0.1 localhost
127.0.0.1 laravel.dev
Also, the following lines are uncommented both in wamp/../conf/httpd.conf and in wamp/.../conf/original/httpd.conf:
LoadModule vhost_alias_module modules/mod_vhost_alias.so
Include conf/extra/httpd-vhosts.conf
The content of my .htaccess is the following:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Yet, when I go to http://laravel.dev I get an Internal Server Error - The server encountered an internal error or misconfiguration and was unable to complete your request..
If i remove the .htaccess file from the public folder, then I'll see the Laravel "You have arrived" message. If then, i create a route like this (within the app\routes.php):
Route::get('/newroute', function()
{
return View::make('hello');
});
and then go to http://laravel.dev/newroute I'll end up with a 404 Not Found - The requested URL /newroute was not found on this server.
I am seriously confused and have no idea how I can get past this. I mention (although i think it's clear) that I ran a composer install after cloning the project template, installing the dependencies.
If the htaccess file that you posted was in your /public/ folder, then that's why you're getting a 500 internal server error. That htaccess file was made for the folder that the /public/ folder is in. But since your public folder is the document root, you don't need it.
The htaccess file in the /public/ folder should look like this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
(for WAMP).
Try turning on AllowOverride All on the directory by changing your VirtualHost to:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
<Directory "c:/wamp/www/laravel/public">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I have gone through the same issue and followed the all the treatments given above but virtual host can not be set.
When I inspected file http.conf then I found that inclusion of file httpd-vhosts.conf was commented as given below. Make sure to include httpd-vhosts.conf in httpd.conf.
#Include conf/extra/httpd-vhosts.conf
I have removed the # comment. Restarted the wamp and it was working.
Include conf/extra/httpd-vhosts.conf

Wildcard Subdomain Exceptions

I have a wildcard subdomain enabled and dynamically parse the URL by passing it as-is to my index.php (ex. somecity.domain.com).
Now, I wish to create a few subdomains that are static where I can install different application and not co-mingle with my current one (ex. blog.domain.com).
My .htaccess currently reads:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Can I manipulate this .htaccess to achieve what I need? Can it be done through Apache?
Your .htaccess does nothing useful, as Apache is probably configured with DirectoryIndex index.php. Well, it does move domain.com/a to domain.com/index.php, but I doubt that is what you want.
Your wildcard virtualhost works because you probably have ServerAlias *.domain.com in your configuration, or a single virtualhost and DNS pointing to the address of your server. (When you have a single virtualhost, it shows up for any request, and the first listed virtualhost is the default one)
You have to create new VirtualHosts for the static domains, leaving the default one as, well, the default one :)
Check these tutorials that explain it all.
You'll have to configure apache for those static sub-domains. The "catch-all" site will be the default site configured, so that one will catch the other ones.
I'm not sure I understand completely what you need to accomplish, but it might helpful to setup virtual domains within your Apache configuration file. You can map them to folders on the drive with different applications installed. Each virtual domain is treated much like a root directory. I have my development environment setup locally on my Windows machine a lot like this:
NameVirtualHost *:80
# Begin virtual host directives.
<VirtualHost *:80>
# myblog.com virtual host.
ServerAdmin webmaster#myblog.com
DocumentRoot "c:/apache_www/myblog.com/www"
ServerName myblog.com
ServerAlias *.myblog.com
ErrorLog "c:/apache_www/myblog.com/logs/log"
ScriptAlias /cgi-bin/ "c:/apache_www/myblog.com/cgi-bin/"
<Directory "c:/apache_www/myblog.com/www">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
If this does not help get you on the right track, then try researching the VirtualHost directive to come up with a solution. I find trying to do all this in an .htaccess to be cumbersome and difficult to manage.
I don't know if you have cPanel installed on your host, but I was able to do this by adding a new subdomain * and then sending all that traffic to a particular subdomain, for example: *.domain.com -> master.domain.com. Then you can read out which URL you are at in master.domain.com and go from there.

Categories