简体   繁体   中英

Is there a way to remove '/web' from url in Symfony application without moving content of 'web' directory to root?

I am facing a problem while creating applications using Symfony which is the occurrence of '/web' in the url. I found a way to get rid of this by moving the content of 'web' directory to root directory. But I think that is not a good development practice and there must be some other way. Can anyone let me know if there is some other way of doing this some thing like we do for removing app_dev.php from url using htaccess ?

In my case im working with wamp server and to get rid of "/web" you need to configure a virtual host in httpd-vhosts.conf like this :

<VirtualHost *:80>
    DocumentRoot C:\wamp\www\YourProjectFolder\web
    ServerName projectName.local
</VirtualHost>

I think you shoold do the same in your host server.

If you don't have the possibility to edit http.conf and mod_rewrite is enabled, simply place a .htaccess file in your Document root and redirect every request to the /web folder.

RewriteEngine on
RewriteRule ^(.*)$ /web/$1 [L,QSA]

Do not move /web folder from Symfony. You just need point your vhost or Apache default root into your web directory. For example :

You can changing in httpd.conf :

# ...
DocumentRoot "your_symfony_folder/web"
<Directory "your_symfony_folder/web">
# ...

You can create a .htaccess into project root folder(where is the folder like app, bin, src...):

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /web/$1 [QSA,L]
</IfModule>

I think you guys are sweating it.

Correct me if I am wrong, but I managed to remove it by simply putting everything in the web directory inside the root directory. Then I eliminated app_dev.php, and renamed app.php into index.php.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM