I got a rather easy problem. How do I remove the path to my website called domain.com?
I've got a lampp server where I put one folder called "domain" in the htdocs folder and to access my website I need to write domain.com/domain instead of just domain.com. And when I write domain.com I come to the usual xampp website
There are a few options, but the easiest is probably using some URL rewriting given your current setup.
mod_rewrite in .htaccess
In your htdocs folder create a .htaccess file:
RewriteEngine On
RewriteBase /
# If the URL does not already exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# or directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /domain/$1 [QSA,L,NC]
Virtual hosting with Apache
You could also edit your VirtualHost container in the Apache configuration to change the directory as well. If you are running XAMPP then I have previously written about using virtual hosts with it on my blog.
For example:
<VirtualHost *:80>
ServerAdmin name#domain.com
DocumentRoot c:\xampp\simonholywell.com\pub
ServerName simonholywell.localhost
<Directory c:\xampp\simonholywell.com\pub>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
A development server for teams (or individuals)
I have also written a large article on setting up a development or staging server for a team as well, which would be good reading if you are setting up such a system. It allows you to simply add a folder on the server and it is immediately available as a subdomain without any further configuration. This is something called mass virtual hosting.
You need to add a virtual host, check the apache name based virtual host documentation. If you're running on windows you could follow this guide, if you're on linux/unix you could try the following guide
Related
few hours later, i need help. I trie to rewrite the url for using wildcard subdomains.
My domains will be *.domain.com - for example mytest.domain.com
For every subdomain is a subfolder unter www.domain.com/sdom/content/mytest
I've setup the apache/nginx server. For testing i upload a index.html inside the "content" folder.
If i type mytest.comain.com this index.html will display. So now i upload the .htaccess file inside this folder to route from here to the destinations (in this example to the "mytest" folder).
I trie a lot of thiks, at least this
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$
RewriteRule (.*) /httpdocs/domain/sdom/content/$1/index.html
i call mytest.domain.com but it wont go to the subfolder, it go to the maindomain.
If i delete the htaccess file, the index.html of the "content" folder will display.
After rewriting the url in the adressfield of the browser shoul display mytest.domain.com - not the new path to the subfolder etc.
What i have to do, that is works ?
UPDATE
subdomains route to -> mainfolder
subdomains should route by htaccess to folder that has the same name of the subdomain
So i trie htacess
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.tld$
RewriteRule ^$ /subdomainfolder/index.html
With .htaccess files you can't. Here mytest.domain.com and www.domain.com are different hostnames. So inevitably an external redirect will happen.
If you want different domains run by one physical server you should use virtual hosts:
<VirtualHost *:80> # Change this to *:443 if you use SSL/TLS
ServerName mytest.domain.com # Your domain name
DocumentRoot $SRV_ROOT/httpdocs/domain/sdom/content/mytest/ # assuming $SRV_ROOT is set to root of your server
<Directory "$SRV_ROOT/httpdocs/domain/sdom/content/mytest/">
Require all granted # on Apache 2.4
# Below are instructions for Apache 2.2
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
You'll need to restart your server each time you add a subdomain, as well as having a DNS record or local record in /etc/hosts file if you test locally.
I want to host two instances of the same Symfony2 application on one Apache server. Each application should be addressed like so:
http://myserver/app1/
http://myserver/app2/
To do so I have set up two port based virtual hosts in Apache plus the third one on port 80 that redirects folder requests to proper vhosts:
<VirtualHost *:80>
DocumentRoot /var/www
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/app1/(.*)$
RewriteRule ^ http://%{HTTP_HOST}:9999/%1 [L]
RewriteCond %{REQUEST_URI} ^/app2/(.*)$
RewriteRule ^ http://%{HTTP_HOST}:8888/%1 [L]
</VirtualHost>
<VirtualHost *:9999>
DocumentRoot /var/www/app1/web
<Directory /var/www/app1/web>
</Directory>
</VirtualHost>
<VirtualHost *:8888>
DocumentRoot /var/www/app2/web
<Directory /var/www/app2/web>
</Directory>
</VirtualHost>
That works perfectly as http://myserver/app1/ is redirected to http://myserver:9999 and http://myserver/app2/ is redirected to http://myserver:8888 (the URL in browser changes). I want the URL in web browser to stay as http://myserver/app1 or http://myserver/app2.
I can do this by adding switch 'P' to RewriteRule, like so:
RewriteRule ^ http://%{HTTP_HOST}:9999/%1 [L,P]
This however creates problem, because now Symfony sees all requests to be coming from port 80 and redirects them back to that port not to the proper virtual host. I think one way to fix this issue would be to force Symfony2 to prepend all requests with the proper application name.
I tried to do so by modifying generateUrl method in vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller.php to always add application name in front of generated URL and it worked but only for page requests (assets were missing for example).
So my question is if there is a way to full Symfony into thinking that all requests should go back to proper 'app' URL?
My suggestion is that you don't try to do this via Apache configuration. You can configure each Symfony application to live in a subfolder, see:
http://www.yegods.it/2015/01/30/install-symfony-app-in-a-subfolder-of-an-existing-site/
You only need to edit app.php, app_dev.php and composer.json (for assets).
I'm using Wampserver on my windows computer, and my colleague is working on a mac with MAMP installed.
I changed my .htaccess file to get rid of the /public/ in the url, which worked fine, but this doesn't work on my buddy's computer with MAMP.
I have read you need to put all the files from the public folder in the root of the directory and change the paths.php and index.php. I've done this and it's not working because it is installed in a subfolder under the MAMP root, even tho I changed my .htaccess to adapt to this.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /laravel/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I've been looking at this all day and it's really annoying me that I can't find the solution.
So what is the best and secure way to do this? how do I need to do this to be able to let it work on MAMP and a shared hosting? (and if possible also wampserver, altho that's not a requirement)
I'm not a fan of virtual hosts on MAMP, if I need to buy MAMP PRO to avoid this then I will, that's not a problem :-). If this is only possible through virtual hosts, then I'll have to do it I guess.
Thanks for the help guys and gals!
Or you could both use the in-built php server that comes with artisan
$ php artisan serve
You don't need to manually edit any Apache files when doing this sort of thing in MAMP. Just select the directory you want to use for www using the option in the control panel:
You should setup up a vhost and add the domain to your hosts file. Don't do this through .htacces.
httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot /path/to/your/project/public
ServerName dev.yourproject.com
</VirtualHost>
Now edit your hosts file: http://helpdeskgeek.com/windows-7/windows-7-hosts-file/
Add this to your hosts file
127.0.0.1 yourproject.com
Now restart everything and your project should be available from http://dev.yourproject.com. Please don't use .htacces for this it is not necessary.
You can also try:
php -S localhost:7000 -t public/
This will fire up the PHP build in server on localhost:7000. Run the command from with the root of your project folder.
http://www.php.net/manual/en/features.commandline.webserver.php
I dont know how to get CakePHP to run in a virtual host on my local machine. I can get the code to work on the default http://localhost:8888/caketest/ but cant get it to work from http://cakeapp.local:8888/ where I get the warning
"URL rewriting is not properly configured on your server. 1) Help me configure it 2) I don't / can't use URL rewriting"
In MAMP's httpd.conf I added
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "/Users/me/Documents/path/to/root/root"
ServerName cakeapp.local
</VirtualHost>
I saw in the help page that it expects
Options FollowSymLinks
AllowOverride All
# Order deny,allow
# Deny from all
but this crashed MAMP
both are CakePHP 2.4.9 with no changes to the default download
Edit: The not working files in /Users/me/Documents/path/to/root/root which dont work were copied to /Applications/MAMP/htdocs where they then worked, so it is an issue with the virtual host
Edit 2:
I thought I had found a solution but It looks like I was wrong. I changed the virtual host to point directly to /app/webroot which has made the default page show correctly, I then proceeded to add the DebugKit plugin (which I have working in a different local host file and the rewrites for its files still dont work.
For example app/Plugin/DebugKit/webroot/css/debug_toolbar.css gets loaded on http://localhost:8888/caketest/debug_kit/css/debug_toolbar.css but the file in the virtual host http://cakeapp.local:8888/debug_kit/css/debug_toolbar.css returns a 404 error (the plugin works), the files just dont get loaded.
If you copied the code from /Application/MAMP/htdocs to /Users/me/Documents/path/to/root/root, did the .htaccess file get copied across as well? This hidden file is often left behind.
OK, I think this works, the last time I tried to fix the directory it was not pointing at the correct directory.
I added the following to the httpd.conf:
<Directory "/Users/me/Documents/path/to/root/root">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
replace with this in your .htaccess file , it worked for me.
RewriteEngine On
RewriteBase /path/to/cake/app
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
I have a RoR app running on a server using Apache as the web server. I also have an instnace of moodle, an LMS based on PHP running. I have placed the web root of moodle inside the RoR space and for the most part it is working ok.
Inside moodle, if I go to sitename.com/moodle/my RoR intercepts that request and reports that it cannot find the page. If I go to sitename.com/moodle/my/index.php it works fine.
I tried creating a new virtual server but adding a second server running on 443 didnt work (the RoR based site is all under ssl).
Does anyone know of a way to tell RoR to ignore the moodle dir or get RoR to automatically detect and append the index.php to the path.
Me to had a same issue below is the apache2 config for the same kind of issue as describe below.
Example folder is the rails application folder and "/en/blog" are the folder path in public folder of rails application in which i had a wordpress install so below configuration allow's apache to turn off passenger for a request made to "http:/example.com/en/blog" so this request is not process by passenger and this request is service as a normal php request so i was able to have a wordpress blog and a rails application running on same server.
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/example/public
#RailsEnv production
<Directory /var/www/example/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
<Location /en/blog>
PassengerEnabled off
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /en/blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /en/blog/index.php [L]
</IfModule>
</Location>