Hide /public in URL, Symfony in subfolder - .htaccess

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]

Related

.htaccess redirect, remove .html, remove subfolder, remove index.html

I want to achive a few things with my htaccess.
Redirect depending on browser language (/en/ or /pl/).
Remove subfolder from new path (mypage.com/eng/index.html to mypage.com/index.html)
Remove index.html from main page (mypage.com/index.html to mypage.com)
Remove any others .html.
For now I have something like this
RewriteEngine on
# language starts with PL
RewriteCond %{HTTP:Accept-Language} ^pl [NC]
>RewriteRule ^$ /pl/$1 [L,R=301]
>
># else redirect to the English version
>RewriteRule ^$ /en/$1 [L,R=301]
>
>
>
# remove index.html from home page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.(php|html)\ HTTP [NC]
RewriteRule (^|/)index\.(php|html)$ /%1 [NC,R=301,L]
# remove .html from the link
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
It almost works (atleast 1,3,4) but I have problem with removing /en/ subfolder from path. I've tried many things but nothing works with my current code properly.
Thanks in advance.

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

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!

htaccess redirection virtual folder

i just got a FTP access to an old server, with architecture:
index.php
page1.php
page2.php
.htaccess
archives/
- page1.php
- page2.php
- ...
new/
- Web/
- frontend.php
- Images/
- ...
- CSS/
- ...
The new site is accessible requesting on /, but i want the old site (the page1.php, page2.php ...) to be accessible requesting on /old/
I don't want to move all files into an 'old' folder, i would like to use only htaccess file, rewriting the address.
I spent 4 hours on it, but i can't get any solution.
Here is an example of my last htaccess, working for the new website but not for the old one:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^old/css/(.*).css$ css/$1.css [QSA,L]
RewriteRule ^old/images/(.*)$ images/$1 [QSA,L]
RewriteRule ^old/files(.*)$ files$1 [QSA,L]
RewriteRule ^old. index.php [QSA,L]
RewriteRule ^css/(.*).css$ new/Web/css/$1.css [QSA,L,NS]
RewriteRule ^images/(.*)$ new/Web/images/$1 [QSA,L,NS]
RewriteRule ^files(.*)$ new/Web/files$1 [QSA,L,NS]
RewriteCond "%{REQUEST_FILENAME}" !-f
RewriteRule .* new/Web/frontend.php [L]
Thks !

How can I make a htaccess redirect without keeping the path?

I am really confused... I have searched and experimented, but can't seem to get anything to work. So I gave up and asked here :)
How can I redirect /subfolder to root, but every page inside the subfolder should be redirected to root?
/subfolder redirects to root
/subfolder/another-folder redirects to root (not root/another-folder)
Thanks.
To redirect requests from /subfolder to / (to the root folder) ,you can use the following Rule in your htaccess file:
RewriteEngine on
RewriteCond %{THE_REQUEST} /subfolder/(.*)\sHTTP [NC]
RewriteRule ^.+$ /%1 [NE,L,R]
The RewriteRule above will redirect any request from /subfolder/foobar to /foobar but you will get a 404 not found error since /foobar doesn't exist in your /root fodder.
To solve this ,you need a RewriteRule to internally rewrite requests from /root to /subfolder .The following rule will Internally map http://example.com/foobar to http://example.com/subfolder/foobar .The redirection from root to the subfolder is invisible.
Add the following right bellow the subfolder to /root redirection rule
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /subfolder/$1 [L]
EDIT :
My apologies. I misread your question. If you want to redirect your /subfolder requests to just the root folder ,try this:
RewriteEngine on
RewriteCond %{THE_REQUEST} /subfolder/(.*)\sHTTP [NC]
RewriteRule ^.+$ / [NE,L,R]

2 domains, htaccess redirect one to index.html but not the other

I'm working on a site that has 2 domains pointing to the same public_html folder.
The server server index.html by default. My code uses htaccess to route all calls to index.php but I only want this to happen for the development URL for now and not the live URL.
I tried routing live.com and www.live.com to www.live/index.html - but I get a redirect loop as I don't know how to make it break if index.html is in the URL.
Can anyone help?
I tried:
# Disable live domain
RewriteCond %{HTTP_HOST} ^live.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.live.com$
RewriteRule (.*)$ http://www.live.com/index.html [L]
Thanks!
# Disable live domain
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?live\.com$
RewriteCond $1 !^index\.html
RewriteRule ^(.*)$ http://www.live.com/index.html [L]

Resources