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.
Related
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
I am a beginner for Symfony and following the Symfony documentation and it has a create page tutorial
and after creating this this when I test this using the browser,
I can access it using the following URLs
localhost:8000/lucky/number and
localhost:8000/app_dev.php/lucky/number
but when I try to access it using the usual way like
localhost/appname/lucky/number
it gives 404 and I use Ubuntu with Apache2 localhost so I need to know the idea behind this Symfony3 routing and why I cannot access the page using usual localhost/cmstest/lucky/number
Thanks
Following the Symfony doc, this is how your vhost should looks like:
<VirtualHost *:80>
DocumentRoot /var/www/MySymfonyProject/web
<Directory /var/www/MySymfonyProject/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
<Directory /var/www/MySymfonyProject/web/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
ErrorLog /var/log/apache2/MySymfonyProject_error.log
CustomLog /var/log/apache2/MySymfonyProject_access.log combined
</VirtualHost>
Now that you have a clean vhost, here are some details/instructions:
All terminal commands are done as admin (sudo).
In terminal, run this command a2enmod rewrite
In terminal, as you don't use any URL, make sure to disable the default vhost a2dissite 000-default.conf
In terminal, make sure to enable your site vhost a2ensite myVhost.conf
Make sure your project directory is right /var/www/MySymfonyProject
In terminal, restart apache service with service apache2 restart
Access your site through localhost or localhost/app_dev.php (you don't have to specify the bundle name)
Because you have to use the web/ directory (which is the public root of your application, only this directory should be accessible using the browser).
When using server:run, it'll use web/ as your server root automatically. When accessing via the directory structure, include it in the URL: http://localhost/appname/web/lucky/number
Hewwo PM-Riabel~
Can you paste here your virtual-host config?
Your first problem may be in it...
Do you have only one virtual-host active on your machine?
I would guess you try to view it from Linux (correct me if it's not the case)
You should set a fictive URL to your hosts file (myurl.com) and redirect it to 127.0.0.1 (localhost)
Then you can configure your virtual-host to work with this same URL. (Better do it when you want to work multiple projects)
Cordially,
Preciel.
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)
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
I have an installation of Laravel on Wampserver. The directory is as follows:
C:\wamp\www\laravel
Now URLs are like this:
http://localhost/laravel/public/index.php/home/index
So I used the following htaccess code
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]
To reduce the URL to
http://localhost/laravel/public/home/index
But the laravel framework insists that all application files reside in the public folder.
So I would like to know what I need to add to (or subtract from) the htaccess file so that the URL can look like
http://localhost/laravel/home/index
Thanks
When testing locally I do one of two things.
Create a new .htaccess below the public directory with the following.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Create a new virtual host. With WAMP you can navigate to C:\wamp\bin\apache\YOUR APACHE VERSION\conf\extra and find your httpd-vhosts.conf file, in there you can see example virtual hosts. Here's one of mine:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
</VirtualHost>
Make sure that your vhosts configuration file is being included. Open up your httpd.conf file and search for the vhosts file, uncomment the include line if it's commented out. Then I open the CLI and enter notepad "C:\windows\system32\drivers\etc\hosts" which opens up your hosts file. Underneath the item that mentions localhost place your new host. Here's an example.
127.0.0.1 laravel.dev
Make sure you restart Apache and bingo, you should be able to navigate to http://laravel.dev and you won't have any annoying public directory. This is how I achieve it, as I prefer the nicer looking virtual host rather then a long winded localhost URL.
Hope this helps.
I finally figured a way out. First of all, I had to open and edit my Apache httpd.conf by selecting it from the Wamp Aestran tray menu. The I had to uncomment the line
#Include conf/extra/httpd-vhosts.conf
After that, I opened the file which is located at the
<wampdirectory>/bin/apache/apache.x.y.z/conf/extra/httpd-vhosts.conf
then I added the following lines.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
Options Indexes FollowSymLinks
<Directory "C:/wamp/www">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
#If you want to allow access from your internal network
# For specific ip addresses add one line per ip address
#Allow from 192.168.0.100
# For every ip in the subnet, just use the first 3 numbers of the subnet
#Allow from 192.168.0
</Directory>
</VirtualHost>
## must be first so the the wamp menu page loads when you use just localhost as the domain name
<VirtualHost *:80>
DocumentRoot "C:/wamp/sites/laravel/public"
ServerName laravel.dev
Options Indexes FollowSymLinks
<Directory "C:/wamp/sites/laravel/public">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
#If you want to allow access from your internal network
# For specific ip addresses add one line per ip address
#Allow from 192.168.0.100
# For every ip in the subnet, just use the first 3 numbers of the subnet
#Allow from 192.168.0
</Directory>
</VirtualHost>
The next step was to edit my hosts file at C:\windows\system32\drivers\etc
and added
127.0.0.1 laravel.dev
Then restarted Wamp and it worked. Thanks to you guys for pointing me in the right direction. Really Appreciate it
The easiest way I got this working on my local dev environment was to do the following:
(Assuming you have WAMP installed in C:\WAMP)
Create the following folder:
c:\wamp\www\laravel
Download laravel and put the contents in the above directory. You will know you have done it right if you can browse to hxxp://localhost/laravel/public and get the opening screen. However, this isn't good enough. We want to get that screen by going to http://localhost/laravel
So then we do the following:
Create a textfile containing the following:
Alias /laravel "c:/wamp/www/laravel/public"
<Directory "c:/wamp/www/laravel/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Allow from all
</Directory>
Save this file as laravel.conf in the c:\wamp\alias directory.
Finally, restart your wampserver.
You should now be able to surf to http://localhost/laravel
Note that the above is strictly for a local development environment.
You're gonna end up with your code and your public folder residing in the same place, which most people do not recommend. I'd suggest you take advantage of using a local web server.
Why not make mysite.dev point to laravel/public directory so you could just use http://mysite.dev everytime, you have cleaner and shorter URL's too?
As a newb to WAMP and Laravel, I struggled at bit but did get the virtualhost thing to work on my WIN7PRO 64-bit box. In WAMPSERVER/Apache/hppd.conf at the end of the file, I added:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot C:/webapp/public
ServerName webapp
<Directory C:/webapp/public >
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from All
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/wamp/www
ServerName localhost
</VirtualHost>
and I added:
127.0.0.1 webapp
to the hosts file. (I was never successful editing the vhosts files, as many posts on the web suggested.)
These changes allow me to get to my Laravel test app in my browser via
http://webapp
(and also, via just http://127.0.0.1)
and, to get to all my other sites, via:
http://localhost/devsite/whatever..