Intereting Posts

Symfony удаляет первые три символа из маршрута

У меня простое приложение Symfony 2.8. На локальном хосте он отлично работает. Но когда я загружаю его для совместного использования хостинга, работает только маршрут «/». Но в каждом маршруте длиной> = 4 символа первые три символа исчезают.

Например:

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" ... 

Это происходит даже на localhost, когда я использую .htaccess, чтобы перенаправить все прямой доступ к веб-каталогу в корневой каталог. У меня есть решение .htaccess отсюда .

/.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> 

Маршрутизатор: вывод отладки

  -------------------------- ---------- -------- ------ ----------------------------------- 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 -------------------------- ---------- -------- ------ ----------------------------------- 

У меня есть default 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> 

С этой конфигурацией и компонентом paragonie / random_compact версии 1.4 я иногда получаю ошибку, и я могу обработать ее путем обновления страницы.

Я предлагаю вам эту альтернативу, используя vhost и symfony default .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> 

И веб / .htaccess fil (он немного длинный, но я не нашел его в Интернете)

 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>