Symfony 5 EasyAdmin 2.x 'admin' route not working - .htaccess

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!

Related

Hide /public in URL, Symfony in subfolder

So I have this structure:
root
- webapp
- wordpress
- some_php_files
I'm trying to redirect only the files in /webapp and not the rest in root. Remove public if webapp before.
show in url | instead of
domain.com/webapp | domain.com/webapp/public
domain.com/webapp/page | domain.com/webapp/public/page
I manage to redirect everything or nothing.
RewriteEngine On
RewriteBase /webapp/
RewriteCond %{THE_REQUEST} public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^(.*)$ public/index.php?$1 [L,QSA]

Laravel 5.4 Redirection in the server

I have a Laravel 5.4 project under the folder www of Wampserver64.
The project folder name is AxilogicV2.
When I visit localhost/AxilogicV2 it will take me to the login screen, but after login succeeds it takes me to 'localhost/'. (The form should make a post request to itself ('/') and will be redirected to ('/view').
Every redirection ignores 'AxilogicV2'.
Example: localhost/AxilogicV2/view/9408 => localhost/view/9408.
Here is my .htaccess file. I tried a bunch of redirect rules but didn't work.
Options -MultiViews
RewriteEngine On
RewriteBase /AxilogicV2
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
In httpd.conf file Rewrite is enabled and Override is set to All.
Edit: I took out the index.php from public folder and made appropriate corrections so that it will find the right bootstrap folder and access autoload.php and app.php

URL Redirect through .Htaccess doesn't work in Php Codeigniter

I want to that when I enter localhost/projectname/index.html it will redirect to
http://localhost/service/welcome/index
For this I write that in .htaccess but it doesn't work
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Redirect /index.html http://localhost/service/welcome/index
How can I do that?
In codeigniter there is no files are calling in URL. All what Codeigniter do is use MVC Structure to render view.
As well as if you access anything on root folder(index.html or index.php) it will redirect to application folder. Then default controller is Trigger out.
cz in root there is file call index.php, there you can see
$application_folder = 'application';
$system_path = 'system';
And you can take look at this
routes - config/routes.php
controller - controller/
model - model/
view - view/
and we use .htaccess to remove index.php in URL.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
if you want to add .html or .php end of URL
in config/config.php
/*
|--------------------------------------------------------------------------
| URL suffix
|--------------------------------------------------------------------------
|
| This option allows you to add a suffix to all URLs generated by CodeIgniter.
| For more information please see the user guide:
|
| http://codeigniter.com/user_guide/general/urls.html
*/
$config['url_suffix'] = '';

Remove subfolder with htaccess

This is the architecture of my website :
/
app/
index.php
...
libs/
lib1/
file.php
lib2/
...
I need to access index.php by this url : domain.com/index.php
I tried this :
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)app
RewriteRule ^(.*)$ app/$1 [L]
It works, but inside my index.php, I call for example :
include('../libs/lib1/file.php');
It's doesn't work because this path refer to root now...
And I can't access to domain.com/libs anymore, because it's looking for domain.com/app/libs.
How can I do ?
The include() shouldn't care what the path the browser sees. That should be based on the local filesystem on the server. But your rules are affecting direct access to the libs, so try adding a few more conditions:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^app/
RewriteRule ^(.+)$ app/$1 [L]
RewriteRule ^$ app/index.php [L]
This makes it so requests for existing files or content won't get routed through the app folder.

URL rewrite to remove trailing folder name

We have a server, and have several folders under the /var/www/ folder.
We have pointed our domain name to the IP of the server, and by default we expect to load one folder as the website (since its not possible to point a folder with DNS).
I have written .htaccess in such a way that when you enter the IP or the domain name, the request redirects to the website folder.
However, whenever we enter the IP or the domain name, the name of the folder is getting added to the URL.
Here is the present .htaccess:
Options +FollowSymlinks -Multiviews
#DirectoryIndex folder/
RewriteEngine on
ReWriteBase /
RewriteRule ^$ /folder [L]
RewriteRule ^$ folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+folder/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^folder/)^(.*)$ /folder/$1 [L,NC]
where the folder is the folder's website
so,
www.domain.com
becomes
www.domain.com/folder/
Is there a way to rewrite the URL to remove the folder name?
Thanks in advance :)
EDIT : Added .htaccess code
Have your rule like this in DocumentRoot/.htacess:
DirectorySlash On
Options +FollowSymlinks -MultiViews
RewriteEngine on
ReWriteBase /
# redirect /folder/abc123 to /abc123
RewriteCond %{THE_REQUEST} \s/+folder/(\S*) [NC]
RewriteRule ^ /%1 [R=301,L,NE]
# skip rewrites for real files/directories
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule !^(index\.)?$ - [L]
# route everything internally to /folder
RewriteRule ^((?!folder/).*)$ folder/$1 [L,NC]
It sounds like you made an external redirect instead of an internal rewrite. An external redirect is denoted by the [R] flag (with optional parameter) and causes Apache to send a 301 or 302 header back to the client with a different url that client should request. This causes the client to show the new url in the address bar.
What you want is an internal rewrite. When you request the url, the url is internally rewritten to the place where the resource is actually located. You do this by omitting the [R] flag, and not using a domain name in the rewritten part. It typically looks something like this:
RewriteCond %{REQUEST_URI} !^/folder
RewriteRule ^(.*)$ /folder/$1 [L]

Resources