3

I add the following lines in my .htaccess file:

# Prevent direct access to the "public" folder - redirect to root
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /public/
RewriteRule ^public/(.*) /$1 [R=302,L]

# Redirect Trailing Slashes If Not A Folder...
# - but look for the file in the "public" folder
#   (ensure we are not already in the "public" folder)
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{DOCUMENT_ROOT}/public/$1 !-d
RewriteRule ^(.*)/$ /$1 [R=302,L]

# Rewrite "everything" to the "public" subdirectory if not already
# This ignores existing files/dirs in the document root
RewriteCond %{REQUEST_URI} ^/(.*)
RewriteRule !^public/ public/%1

# Handle Front Controller... (as before)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Now my site works just fine without needing the public or index.php in my URL means I can use my site like http://example.com.

But when I try to go http://example.com/admin, it fails although it works on local machine.

My routing file for easyadmin looks like this one:

# File Location: /config/routes/easy_admin.yaml
easy_admin_bundle:
  resource: '@EasyAdminBundle/Controller/EasyAdminController.php'
  prefix: /admin/
  type: annotation

Debug router:

-------------------------- -------- -------- ------ ----------------------------------- 
 Name                       Method   Scheme   Host   Path                               
-------------------------- -------- -------- ------ ----------------------------------- 
_preview_error             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   
app_login                  ANY      ANY      ANY    /login                             
app_logout                 ANY      ANY      ANY    /logout                            
easyadmin                  ANY      ANY      ANY    /admin/                            
home                       ANY      ANY      ANY    /

Note: If I remove my .htaccess file and then http://example.com/public/index.php/admin works just fine.

Would you please someone help how to get rid of this public/index.php working with admin route of EasyAdmin!

Siddiqui Noor
  • 5,575
  • 5
  • 25
  • 41

0 Answers0