我已将sonata admin
添加到我的网站。
在本地,我可以访问路径/admin
,但是当我将其推送到产品环境时却无法访问。尝试访问它时,我得到 404 :
未找到 在此服务器上找不到请求的URL / admin。
我已删除var/cache/prod
中的缓存
万一这是我使用的sonata_admin.yaml
的内容,
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
admin_area:
resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
prefix: /admin
sonata_user_admin_security:
resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml'
prefix: /admin
sonata_user_admin_resetting:
resource: '@SonataUserBundle/Resources/config/routing/admin_resetting.xml'
prefix: /admin/resetting
我是否必须配置一些内容才能访问服务器上的这些路径?还是与.htaccess
文件有关。
任何可能导致此问题的线索?
预先感谢您的帮助!
更新:这是在本地主机上执行debug:router
命令(在生产环境中无法执行)时得到的内容
D:\website>php bin/console debug:router
------------------------------------------ ---------- -------- ------ ----------------------------------------------------
Name Method Scheme Host Path
------------------------------------------ ---------- -------- ------ ----------------------------------------------------
homepage ANY ANY ANY /
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
_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_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_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
webhook_index ANY ANY ANY /mailchimp/webhook/endpoint
admin_app_event_list ANY ANY ANY /admin/app/event/list
admin_app_event_create ANY ANY ANY /admin/app/event/create
admin_app_event_batch ANY ANY ANY /admin/app/event/batch
admin_app_event_edit ANY ANY ANY /admin/app/event/{id}/edit
admin_app_event_delete ANY ANY ANY /admin/app/event/{id}/delete
admin_app_event_show ANY ANY ANY /admin/app/event/{id}/show
admin_app_event_export ANY ANY ANY /admin/app/event/export
admin_sonata_user_user_list ANY ANY ANY /admin/sonata/user/user/list
admin_sonata_user_user_create ANY ANY ANY /admin/sonata/user/user/create
admin_sonata_user_user_batch ANY ANY ANY /admin/sonata/user/user/batch
admin_sonata_user_user_edit ANY ANY ANY /admin/sonata/user/user/{id}/edit
admin_sonata_user_user_delete ANY ANY ANY /admin/sonata/user/user/{id}/delete
admin_sonata_user_user_show ANY ANY ANY /admin/sonata/user/user/{id}/show
admin_sonata_user_user_export ANY ANY ANY /admin/sonata/user/user/export
admin_sonata_user_group_list ANY ANY ANY /admin/sonata/user/group/list
admin_sonata_user_group_create ANY ANY ANY /admin/sonata/user/group/create
admin_sonata_user_group_batch ANY ANY ANY /admin/sonata/user/group/batch
admin_sonata_user_group_edit ANY ANY ANY /admin/sonata/user/group/{id}/edit
admin_sonata_user_group_delete ANY ANY ANY /admin/sonata/user/group/{id}/delete
admin_sonata_user_group_show ANY ANY ANY /admin/sonata/user/group/{id}/show
admin_sonata_user_group_export ANY ANY ANY /admin/sonata/user/group/export
sonata_admin_redirect ANY ANY ANY /admin/
sonata_admin_dashboard ANY ANY ANY /admin/dashboard
sonata_admin_retrieve_form_element ANY ANY ANY /admin/core/get-form-field-element
sonata_admin_append_form_element ANY ANY ANY /admin/core/append-form-field-element
sonata_admin_short_object_information ANY ANY ANY /admin/core/get-short-object-description.{_format}
sonata_admin_set_object_field_value ANY ANY ANY /admin/core/set-object-field-value
sonata_admin_search ANY ANY ANY /admin/search
sonata_admin_retrieve_autocomplete_items ANY ANY ANY /admin/core/get-autocomplete-items
sonata_user_admin_security_login ANY ANY ANY /admin/login
sonata_user_admin_security_check POST ANY ANY /admin/login_check
sonata_user_admin_security_logout ANY ANY ANY /admin/logout
sonata_user_admin_resetting_request GET ANY ANY /admin/resetting/request
sonata_user_admin_resetting_send_email POST ANY ANY /admin/resetting/send-email
sonata_user_admin_resetting_check_email GET ANY ANY /admin/resetting/check-email
sonata_user_admin_resetting_reset GET|POST ANY ANY /admin/resetting/reset/{token}
------------------------------------------ ---------- -------- ------ ----------------------------------------------------
答案 0 :(得分:1)
找到了解决方案:
在 Symfony 4.x 中,我们需要指定特定的重写规则。
我遵循了Symfony 4 documentation。 我只需要执行以下命令即可解决此问题:
composer require symfony/apache-pack
您也可以将此代码添加到Symfony项目的.htaccess
子目录的public
文件中:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /index.php/
</IfModule>
</IfModule>
瞧瞧! /admin
和所有子路径现在都可以在服务器上访问了。