2014-10-06 67 views
0

所有請求都會通過文件web/app.php(類似於index.php),例如對主頁的請求 - adwords-up.com/web/app.php,input - adwords-up.com /web/app.php/login。我想從鏈接中刪除部分web/app.php。在配置.htaccess中,重定向到默認的web/app.php,以便這樣的請求是主要格式 - http://adwords-up.com/和Page login - 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文檔上也有答案

+0

它不工作:\ – 2014-10-06 11:03:47

+0

你有'在Apache中啓用mod_rewrite'? – 2014-10-06 11:04:38

+0

是的。 'var_dump(in_array('mod_rewrite',apache_get_modules()));'布爾真正 – 2014-10-06 12:22:11

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> 

希望它可以幫助