Symfony从路由中移除前三个字符

我有简单的Symfony 2.8应用程序。 在本地主机上,它工作正常。 但是当我上传它共享主机只有“/”路线的作品。 但是,在长度大于等于4个字符的每条path中,前三个字符都会消失。

例如:

I go to domain.com/123456 and Symfony says No route found for "GET 465" I go to domain.com/admin and Symfony says No route found for "GET in" I go to domain.com/blog and Symfony says No route found for "GET g" ... 

它甚至在本地主机上发生,当我使用.htaccessredirect到web目录的所有直接访问到根。 我从这里有.htaccess解决scheme。

/.htaccess

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

/web/.htaccess

 <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /web/ RewriteRule ^(.*)$ /$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ app.php [QSA,L] </IfModule> 

路由器:debugging输出

  -------------------------- ---------- -------- ------ ----------------------------------- Name Method Scheme Host Path -------------------------- ---------- -------- ------ ----------------------------------- _wdt ANY ANY ANY /_wdt/{token} _profiler_home ANY ANY ANY /_profiler/ _profiler_search ANY ANY ANY /_profiler/search _profiler_search_bar ANY ANY ANY /_profiler/search_bar _profiler_purge ANY ANY ANY /_profiler/purge _profiler_info ANY ANY ANY /_profiler/info/{about} _profiler_phpinfo ANY ANY ANY /_profiler/phpinfo _profiler_search_results ANY ANY ANY /_profiler/{token}/search/results _profiler ANY ANY ANY /_profiler/{token} _profiler_router ANY ANY ANY /_profiler/{token}/router _profiler_exception ANY ANY ANY /_profiler/{token}/exception _profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css _twig_error_test ANY ANY ANY /_error/{code}.{_format} admin-index ANY ANY ANY /admin admin-settings ANY ANY ANY /admin/nastaveni admin-blog-index GET ANY ANY /admin/blog/ admin-blog-new GET|POST ANY ANY /admin/blog/napsat-clanek admin-blog-show GET ANY ANY /admin/blog/{id} admin-blog-edit GET|POST ANY ANY /admin/blog/{id}/upravit admin-blog-delete DELETE ANY ANY /admin/blog/{id} blog-detail ANY ANY ANY /blog/clanek/{id}/{articleSlug} blog-index ANY ANY ANY /blog/{tagSlug}/{currentPage} homepage ANY ANY ANY / about-us ANY ANY ANY /o-projektu travelTimeline ANY ANY ANY /plan-cesty -------------------------- ---------- -------- ------ ----------------------------------- 

我有默认的routing.yml和security.yml

你能看到一个错误吗?


– -编辑 – –

新/.htaccess

 <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On # Explicitly disable rewriting for front controllers RewriteRule ^/web/app_dev.php - [L] RewriteRule ^/web/app.php - [L] # Fix the bundles folder RewriteRule ^bundles/(.*)$ /web/bundles/$1 [QSA,L] RewriteCond %{REQUEST_FILENAME} !-f # Change below before deploying to production RewriteRule ^(.*)$ /web/app.php [QSA,L] #RewriteRule ^(.*)$ /web/app_dev.php [QSA,L] </IfModule> 

/web/.htaccess(原文来自Symfony)

 # Use the front controller as index file. It serves as a fallback solution when # every other rewrite/redirect fails (eg in an aliased environment without # mod_rewrite). Additionally, this reduces the matching process for the # start page (path "/") because otherwise Apache will apply the rewriting rules # to each configured DirectoryIndex file (eg index.php, index.html, index.pl). DirectoryIndex app.php # By default, Apache does not evaluate symbolic links if you did not enable this # feature in your server configuration. Uncomment the following line if you # install assets as symlinks or if you experience problems related to symlinks # when compiling LESS/Sass/CoffeScript assets. # Options FollowSymlinks # Disabling MultiViews prevents unwanted negotiation, eg "/app" should not resolve # to the front controller "/app.php" but be rewritten to "/app.php/app". <IfModule mod_negotiation.c> Options -MultiViews </IfModule> <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] # Sets the HTTP_AUTHORIZATION header removed by apache RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] # 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 start page 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] # Rewrite all other queries to the front controller. RewriteRule .? %{ENV:BASE}/app.php [L] </IfModule> <IfModule !mod_rewrite.c> <IfModule mod_alias.c> # When mod_rewrite is not available, we instruct a temporary redirect of # the start page to the front controller explicitly so that the website # and the generated links can still be used. RedirectMatch 302 ^/$ /app.php/ # RedirectTemp cannot be used instead </IfModule> </IfModule> 

有了这个configuration和组件paragonie / random_compact版本1.4我只有时得到错误,我可以通过页面刷新处理。

我为你提供这个选择,使用虚拟主机和symfony默认的.htaccess

 <VirtualHost 192.168.0.1:80> serverName mydomain.com DocumentRoot /var/www/myproject/web <Directory /> Header set Access-Control-Allow-Origin "*" Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/myproject/web> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error-myproject.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel notice CustomLog ${APACHE_LOG_DIR}/access-myproject.log combined </VirtualHost> 

和web / .htaccess文件(这是有点长,但我没有找到它在线)

 DirectoryIndex app.php # By default, Apache does not evaluate symbolic links if you did not enable this # feature in your server configuration. Uncomment the following line if you # install assets as symlinks or if you experience problems related to symlinks # when compiling LESS/Sass/CoffeScript assets. # Options FollowSymlinks # Disabling MultiViews prevents unwanted negotiation, eg "/app" should not resolve # to the front controller "/app.php" but be rewritten to "/app.php/app". <Ifmodulee mod_negotiation.c> Options -MultiViews </Ifmodulee> <Ifmodulee 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] # Sets the HTTP_AUTHORIZATION header removed by apache RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] # 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 start page 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] # Rewrite all other queries to the front controller. RewriteRule .? %{ENV:BASE}/app.php [L] </Ifmodulee> <Ifmodulee !mod_rewrite.c> <Ifmodulee mod_alias.c> # When mod_rewrite is not available, we instruct a temporary redirect of # the start page to the front controller explicitly so that the website # and the generated links can still be used. RedirectMatch 302 ^/$ /app.php/ # RedirectTemp cannot be used instead </Ifmodulee> </Ifmodulee>