search

Home  >  Q&A  >  body text

Routing issues in symfony2 project

My project home page URL is http://localhost/lcode/web/app_dev.php
Then all URLs accessed by {{ path('abc') }} will have localhost/lcode/web/app_dev.php
This paragraph
Now I want to use gzl to replace this
For example, the home page access is http://gzl

仅有的幸福仅有的幸福2752 days ago456

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-05-16 16:46:43

    It’s ok.
    os: windows 7
    server: nginx

    1. Configure nginx

    Create a new virtual host in the nginx.conf file. The configuration code is as follows:

    server {
        listen 80;
    
        server_name www.caiwen.org;
        try_files $uri $uri/ /app_dev.php?$query_string;
    
        # 如果URL中包含app_dev.php,则转发为伪静态格式
        rewrite ^/app_dev\.php/?(.*)$ / permanent;
    
        location / {
            index app_dev.php;
            root  D:/WebRoot/caiwen/codes/web;
            try_files $uri @rewriteapp;
        }
    
        location @rewriteapp {
            rewrite ^(.*)$ /app_dev.php/ last;
        }
    
       location ~ \.php {
            root           D:/WebRoot/caiwen/codes/web;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  app_dev.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    

    2. Configure hosts file

    Under Windows, use Notepad to open the C:WindowsSystem32driversetchosts file and add a line

    127.0.0.1   www.caiwen.org
    

    Under ubuntu, vim /etc/hosts

    It’s OK.
    In this way, you can use www.caiwen.org to access the website in Browser without adding /codes/web/app_dev.php at the end.

    You can refer to my configuration file to complete your configuration. Pay attention to the amazing path.

    reply
    0
  • Cancelreply