2014-10-06 2 views
0

Все запросы проходят через файл web/app.php (аналогично index.php), например запрос на главную страницу - adwords-up.com/web/app.php, input - adwords-up.com /web/app.php/login. Я хочу, чтобы часть веб/app.php была удалена из ссылки. В конфигурации .htaccess переадресуйте на web/app.php по умолчанию, так что запрос для этого был основной формой - http://adwords-up.com/ и страничным логином - http://adwords-up.com/login.Удалить web/app.php ссылки. Symfony2

Существует мой /etc/apache2/sites-available/adwords-up.conf

<VirtualHost *:80> 
# The ServerName directive sets the request scheme, hostname and port t$ 
# the server uses to identify itself. This is used when creating 
# redirection URLs. In the context of virtual hosts, the ServerName 
# specifies what hostname must appear in the request's Host: header to 
# match this virtual host. For the default virtual host (this file) this 
# value is not decisive as it is used as a last resort host regardless. 
# However, you must set it for any further virtual host explicitly. 
ServerName adwords-up 

ServerAdmin [email protected] 
DocumentRoot /var/www/adwords-up/web 
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn, 
# error, crit, alert, emerg. 
# It is also possible to configure the loglevel for particular 
# modules, e.g. 
#LogLevel info ssl:warn 

ErrorLog ${APACHE_LOG_DIR}/error.log 
CustomLog ${APACHE_LOG_DIR}/access.log combined 

# For most configuration files from conf-available/, which are 
# enabled or disabled at a global level, it is possible to 
# include a line for only one particular virtual host. For example the 
# following line enables the CGI configuration for this host only 
# after it has been globally disabled with "a2disconf". 
#Include conf-available/serve-cgi-bin.conf 
</VirtualHost> 

ответ

0

это может помочь вам

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    # Determine the RewriteBase automatically and set it as environment variable. 
    # If you are using Apache aliases to do mass virtual hosting or installed the 
    # project in a subdirectory, the base path will be prepended to allow proper 
    # resolution of the app.php file and to redirect to the correct URI. It will 
    # work in environments without path prefix as well, providing a safe, one-size 
    # fits all solution. But as you do not need it in this case, you can comment 
    # the following 2 lines to eliminate the overhead. 
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ 
    RewriteRule ^(.*) - [E=BASE:%1] 

    # Redirect to URI without front controller to prevent duplicate content 
    # (with and without `/app.php`). Only do this redirect on the initial 
    # rewrite by Apache and not on subsequent cycles. Otherwise we would get an 
    # endless redirect loop (request -> rewrite to front controller -> 
    # redirect -> request -> ...). 
    # So in case you get a "too many redirects" error or you always get redirected 
    # to the startpage because your Apache does not expose the REDIRECT_STATUS 
    # environment variable, you have 2 choices: 
    # - disable this feature by commenting the following 2 lines or 
    # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the 
    # following RewriteCond (best solution) 
    RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
    RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] 

    # If the requested filename exists, simply serve it. 
    # We only want to let Apache serve files and not directories. 
    RewriteCond %{REQUEST_FILENAME} -f 
    RewriteRule .? - [L] 
    </IfModule> 

добавьте в ваш .htaccess и убедитесь, что rewriteEngine активирован также это общий вопрос с ответами даже на symfon2 doc

+0

ее не работает: \ –

+0

у вас есть 'mod_rewrite' включен в апаче? –

+0

Да. 'exit (var_dump (in_array ('mod_rewrite', apache_get_modules())));' boolean true –

0

Вам необходимо настроить виртуальный хост apache и поместить правильные корневые правила и переписать правила. пример:

<VirtualHost *:80> 
    ServerName adwords-up.com 
    DocumentRoot <path-to-your-codebase>/web 
    DirectoryIndex app.php 
    ErrorLog /var/log/apache2/error.log 
    CustomLog /var/log/apache2/access.log combined 
    RewriteEngine on 
    RewriteOptions Inherit 
    RewriteRule ^/app.php/(.*) http://adwords-up.com/$1 
    RewriteRule ^/(.*) /app.php/$1 [QSA,L] 

    <Directory "<path-to-your-codebase>/web"> 
     Options Indexes FollowSymLinks 
     AllowOverride None 
     Require all granted 
    </Directory> 
</VirtualHost> 

Надеется, что это помогает

Смежные вопросы