How to remove web/ from url (symfony) - url

I am using symfony 3. I want to remove web/ from url like this.
localhost/symfony/web/
to
localhost/symfony/
but I want all my asset (css, js etc) in web folder.
Like other frameworks (codeigniter, cakephp), we access main controller from root not web folder
Anybody can help

I am using this htaccess in the root directory. It could help you.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>

I'd suggest to change the DocumentRoot path in your Virtual Host configuration in Apache.
<VirtualHost *:80>
...
DocumentRoot /path/to/project/web
</VirtualHost>
This way Apache will point to your web/ folder instead of your project root folder and will avoid having the /web/ in your URL.
Hope this helps :)

You can remove it by changing the DocumentRoot path in your Virtual Host configuration in Apache.
Step-1
Open D:\xampp\apache\conf\extra\httpd-vhosts.conf and put below code
<VirtualHost *:80>
ServerName mysite.dev
ServerAlias www.mysite.dev
DocumentRoot "D:/xampp/htdocs/symfony_demo/web"
<Directory "D:/xampp/htdocs/symfony_demo/web">
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
ErrorLog "logs/mysite_error.log"
##CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
And save this file
Step-2
Open C:\Windows\System32\drivers\etc\hosts file and put below code
127.0.0.1 mysite.dev
and save
Step-3
Restart Apache and hit "mysite.dev" in browser

Related

Setup and configure Zend Skeleton Application

I'm new to Zend Framework 2 and have installed the Skeleton Application manually. My application is kept in "D:\xampp\htdocs\zf2". I've created a virtual host but when I point it to the public folder in D:\xampp\htdocs\zf2\public" it gives the error object not found. However, if I have the option other option like "D:\xampp\htdocs\zf2" then it works. I've also tried putting index.php at the end and that also works but it gives output like this.
I've set the virtual host in httpd-vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "D:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
ServerName zf2
DocumentRoot "D:/xampp/htdocs/zf2/public"
<Directory "D:/xampp/htdocs/zf2/public">
#DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and in C:/Windows/System32/Drivers/etc/hosts file I added the line 127.0.0.1 zf2
Can any one help me on this?

How to change the URL from "localhost" to something else, on a local system using wampserver?

On a Windows machine, there's a system running on the local wampserver, but while the application is running on localhost, the URL says otherwise.
While I would expect the URL to be like this based on the directory structure:
http://localhost/pro/include/db_report.php
The developer has managed to do this:
http://ap-mispro/pro/include/db_report.php
So instead of localhost, the URL says ap-mispro.
And both URLs work fine.
How is the second URL made? I tried checking out the wampmanager.ini and wampmanager.tpl but maybe I didn't know what to look for?
WINDOWS + WAMP solution
Step 1
Go to C:\wamp\bin\apache\Apache2.2.17\conf\ open httpd.conf file and change #Include conf/extra/httpd-vhosts.conf to Include conf/extra/httpd-vhosts.conf i.e. uncomment the line so that it can includes the virtual hosts file.
Step 2
Go to C:\wamp\bin\apache\Apache2.2.17\conf\extra and open httpd-vhosts.conf file and add the following code
<VirtualHost myWebsite.local>
DocumentRoot "C:/wamp/www/myWebsite/"
ServerName myWebsite.local
ServerAlias myWebsite.local
<Directory "C:/wamp/www/myWebsite/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
change myWebsite.local and C:/wamp/www/myWebsite/ as per your requirements.
Step 3
Open hosts file in C:/Windows/System32/drivers/etc/ and add the following line ( Don't delete anything )
127.0.0.1 myWebsite.local
change myWebsite.local as per your name requirements
Step 4
restart your server. That's it
WINDOWS + XAMPP solution
Same steps as that of WAMP just change the paths according to XAMPP which corresponds to path in WAMP
Copy the hosts file and add 127.0.0.1 and name which you want to show or run at the browser link. For example:
127.0.0.1 abc
Then run abc/ as a local host in the browser.
They are probably using a virtual host (http://www.keanei.com/2011/07/14/creating-virtual-hosts-with-wamp/)
You can go into your Apache configuration file (httpd.conf) or your virtual host configuration file (recommended) and add something like:
<VirtualHost *:80>
DocumentRoot /www/ap-mispro
ServerName ap-mispro
# Other directives here
</VirtualHost>
And when you call up http://ap-mispro/ you would see whatever is in C:/wamp/www/ap-mispro (assuming default directory structure). The ServerName and DocumentRoot do no have to have the same name at all. Other factors needed to make this work:
You have to make sure httpd-vhosts.conf is included by httpd.conf for your changes in that file to take effect.
When you make changes to either file, you have to restart Apache to see your changes.
You have to change your hosts file
http://en.wikipedia.org/wiki/Hosts_(file) for your computer to know
where to go when you type http://ap-mispro into your browser. This
change to your hosts file will only apply to your computer - not
that it sounds like you are trying from anyone else's.
There are plenty more things to know about virtual hosts but this should get you started.
please refer http://complete-concrete-concise.com/web-tools/how-to-change-localhost-to-a-domain-name
this is best solution ever
for new version of Wamp
<VirtualHost *:80>
ServerName domain.local
DocumentRoot C:/wamp/www/domain/
<Directory "C:/wamp/www/domain/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
After another hour or two I can actually answer my own question.
Someone on another forum mentioned that you need to keep a mention of plain ol' localhost in the httpd-vhost.conf file, so here's what I ended up with in there:
ServerName localhost
DocumentRoot "c:/wamp/www/"
DocumentRoot "C:/wamp/www/pocket/"
ServerName pocket.clickng.com
ServerAlias pocket.clickng.com
ErrorLog "logs/pocket.clickng.com-error.log"
CustomLog "logs/pocket.clickng.com-access.log" common
<Directory "C:/wamp/www/pocket/">
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Exit WAMP, restart - good to go. Hope this helps someone else :)
go to C:\Windows\System32\drivers\etc and open hosts file and add
this
127.0.0.1 example.com
127.0.0.1 www.example.com
then go to C:\xampp\apache\conf\extra open httpd-ajp.conf file and add
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/pojectroot"
ServerName example.com
ServerAlias www.example.com
<Directory "C:/xampp/htdocs/projectroot">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
WINDOWS + MAMP solution
Step 1
Go to S:\MAMPenter code here
\bin\apache\conf\ open httpd.conf file and change
#Include conf/extra/httpd-vhosts.conf
to
Include conf/extra/httpd-vhosts.conf i.e. uncomment the line so that it can includes the virtual hosts file.
Step 2
Go to S:\MAMP\bin\apache\conf\extra and open httpd-vhosts.conf file and add the following code
<VirtualHost myWebsite.local>
DocumentRoot "S:\MAMP\htdocs/myWebsite/"
ServerName myWebsite.local
ServerAlias myWebsite.local
<Directory "S:\MAMP\htdocsmyWebsite/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
change myWebsite.local and S:\MAMP\htdocs/myWebsite/ as per your requirements.
Step 3
Open hosts file in C:/Windows/System32/drivers/etc/ and add the following line ( Don't delete anything )
127.0.0.1 myWebsite.local
change myWebsite.local as per your name requirements
Step 4
restart your server. That's it
This method will work for xamp/wamp/lamp
1st go to your server directory, for example, C:\xamp
2nd go to apache/conf/extra and open httpd-vhosts.conf
3rd add following code to this file
<VirtualHost myWebsite.local>
DocumentRoot "C:/wamp/www/php-bugs/"
ServerName php-bugs.local
ServerAlias php-bugs.local
<Directory "C:/wamp/www/php-bugs/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
For DocumentRoot and Directory add your local directory
For ServerName and ServerAlias give your server a name
Finally go to C:/Windows/System32/drivers/etc and open hosts file
add 127.0.0.1 php-bugs.local and nothing else
For the finishing touch restart your server
For Multile local domain add another section of code into httpd-vhosts.conf
<VirtualHost myWebsite.local>
DocumentRoot "C:/wamp/www/php-bugs2/"
ServerName php-bugs.local2
ServerAlias php-bugs.local2
<Directory "C:/wamp/www/php-bugs2/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and add your host into host file 127.0.0.1 php-bugs.local2

Rails 3 + passenger conf file

I have been trying to install a rails app on a box that originally was used for multiple php applications. I installed passenger and created a conf file but I am confused about how it all works together.
What should my ServerName be if i want to access a Rails app? The box is a debian squeeze running apache2 with passenger module installed. Below is my conf file. I currently have to go to xxx.xxx.xxx.xxx/leoadmin/public to get the application to run properly. I have the following htaccess in the public directory. Which I think is unnecessary if my conf file is configured correctly.
I think my main issue is the misconfiguration of the conf file. I believe the conf file is being loaded but i don't understand why i still need the htaccess for me to see any action.
.htaccess
#PassengerEnabled On
PassengerAppRoot /var/www/leoadmin/
#Options -MultiViews
#PassengerResolveSymlinksInDocumentRoot on
#Set this to whatever environment you'll be running in
RailsEnv production
#RackBaseURI /var/www/leoadmin
vhost config
<VirtualHost *>
ServerName leoadmin
DocumentRoot /var/www/leoadmin/public
<Directory /var/www/leoadmin/public>
Allow from all
</Directory>
Alias /leoadmin /var/www/leoadmin/public
<Location /leoadmin>
SetEnv RAILS_RELATIVE_URL_ROOT "/leoadmin"
PassengerAppRoot /var/www/leoadmin
</Location>
ErrorLog /var/log/apache2/leoadmin-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/leoadmin-access.log combined
</VirtualHost>
I had nothing but pain and more pain trying to get this sorted a few months back, my configuration allows me to do sub URIs, so I'm not sure if that's what you want, but it'll be along these lines. I've never needed a .htaccess file for this setup:
NameVirtualHost *:80 <VirtualHost *:80>
ServerName www.test.co.uk
DocumentRoot /web/rails
<Directory /web/rails>
Allow from all
</Directory>
RailsBaseURI /test
RailsEnv development
<Directory /web/rails_projects/test/>
Options -MultiViews
</Directory>
For me /web/rails is a root directory, from there I have a number of symlinks to my /home/ directory where I store my projects. ServerName is whatever qualified name you're using for the machine that's going to be recognised.
(just in case, I'm running Passenger 3.0.9, and Rails 3.2.11)

Rails 3 Deploy: Multiple rails apps single domain error: No such file or directory - config/environment.rb

Yesterday, I bought a server on Linode. I setup Apache, RVM, Rails, MySQL and have got a single rails app hosted on a domain, following a nice guide from http://library.linode.com/frameworks/ruby-on-rails-apache/ubuntu-10.04-lucid. It also explains how to put multiple rails apps on the same domain, however when I try, I get an error when I access my domain our-portal.com/adm :
No such file or directory - config/environment.rb
Application root: /srv/www/our-portal.com/public_html
Somethings wrong here... anyone have any ideas? I am able to host a single app just fine, but not multiple... Here is my Virtual Host settings
<VirtualHost *:80>
ServerAdmin webmaster#our-portal.com
ServerName our-portal.com
ServerAlias www.our-portal.com
DocumentRoot /srv/www/our-portal.com/public_html/
RailsBaseURI /adm
RailsBaseURI /matrix
ErrorLog /srv/www/our-portal.com/logs/error.log
CustomLog /srv/www/our-portal.com/logs/access.log combined
</VirtualHost>
My applications path is in /srv/www/our-portal.com/adm/ and I linked using
ln -s /srv/www/our-portal.com/adm/public/ /srv/www/our-portal.com/public_html/adm/
ln -s /srv/www/our-portal.com/matrix/public/ /srv/www/our-portal.com/public_html/matrix/
Try by setting the DocumentRoot to the public folder of your application:
DocumentRoot /srv/www/our-portal.org/app/public
I got it working, these are the changes I made.
<VirtualHost *:80>
ServerAdmin webmaster#our-portal.com
ServerName our-portal.com
ServerAlias www.our-portal.com
DocumentRoot /srv/www/our-portal.com/public_html
<Directory /srv/www/our-portal.com/public_html>
Allow from all
</Directory>
RailsBaseURI /adm
RailsBaseURI /matrix
<Directory /srv/www/our-portal.com/public_html/adm>
Options -MultiViews
</Directory>
<Directory /srv/www/our-portal.com/public_html/matrix>
Options -MultiViews
</Directory>
ErrorLog /srv/www/our-portal.com/logs/error.log
CustomLog /srv/www/our-portal.com/logs/access.log combined
</VirtualHost>
I also believe my links were not created correctly. It helped to type
ln -s
and double-click tab (without executing the command) to look at the correct way Unix handles the path for this function. My links looked like this
ln -s /srv/www/our-portal.com/adm/public/ our-portal.com/public_html/adm
ln -s /srv/www/our-portal.com/sitedb-pro/public/ our-portal.com/public_html/matrix
Notice the difference from my old links. Using double-click tab I was able to reference these folders correctly.

How can I force 'www' subdomain w/ Apache2 + Rails + Phusion Passenger?

My clients want to use 301 redirects to force the 'www' subdomain on their sites. So 'example.com/something' resolves to 'www.example.com/somthing' etc.
What I'm trying to do is simply add this to my vhost file:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName example.com
ServerAlias www.*
DocumentRoot /data/apps/example.com/current/public
RailsBaseURI /
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^ http://www.example.com%{REQUEST_URI} [L,R=301]
</VirtualHost>
I've also ensured that mod rewrite was enabled via:
sudo a2enmod rewrite
sudo /etc/init.d/apache2 force-reload
The outcome of my current efforts basically appears to be successful. Apache restarts and everything works as expected EXCEPT the rewrite isn't happening. So both 'www.example.com' and 'example.com' resolve. The browser doesn't get redirected to 'www.example.com' when it should. Any ideas? I've tried reloading the configuration and restarting apache several times but I can't seem to get the rewrite rules working. Am I setting them up in the wrong place by placing them here in the vhost instead of a .htaccess file?
Any advice here would be useful. I'm completely baffled.
Put this below your main VirtualHost entry:
<VirtualHost *:80>
ServerName example.com
RedirectMatch permanent ^/(.*) http://www.example.com/$1
</VirtualHost>
You main VirtualHost should have a ServerName www.example.com entry and no aliases or redirects. Also, mod_rewrite is not required for this redirect.

Resources