Lumen framework routes not working inside a subdirectory - .htaccess

My htdocs folder is like the following:
htdocs:
/server - here all the lumen files are located
/client - angular 1 project
How can I redirect that when I type localhost/server in the url it will redirect me to the public folder inside the server folder.
I've written this for the .htaccess inside the /server folder to redirect everything to the public folder.
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]

Related

(api) .htaccess rewriting for /backend and /frontend folders

I'm trying to host a nuxt + symfony project, and I'm kind of stuck here.
I suppose what I need is some .htaccess rewriting.
I have 2 separate folders :
/
- /backend, which is basically my symfony folder.
- /frontend, containing my nuxt app.
I would need to redirect all of the requests that do not contain "/api" to the /frontend folder, and all requests containing "/api" to "/backend/".
Example :
mydomain.com/articles/5 would redirect to mydomain.com/frontend/articles/5
mydomain.com/api/article/5 would redirect to mydomain.com/backend/article/5
Any help would be really useful,
thank you.
Assuming you have additional .htaccess files in the /frontend and /backend subdirectories that also use mod_rewrite to route the URL then you could do something like the following in the root .htaccess file:
RewriteEngine On
# Rewrite "/api/<something>` to backend
RewriteRule ^api/(.*) backend/$1 [L]
# Everything else rewritten to frontend
RewriteRule (.*) frontend/$1 [L]

Redirection issue on Symfony 5

I try to publish a symfony application on an web server.
The structure of the webserver is :
www
gpexe
config
public
src
var
templates
tests
vendor
I've setup an htaccess on the root folder www:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/gpexe/public/
RewriteRule ^(.*)$ /gpexe/public/$1 [L]
And there's also an htaccess on the public folder generated by Symfony avaliable here.
I managed to access to the main page when typing the root address (www.gpexe.fr), but the css and js link are redirected correctly, for instance :
No route found for "GET /build/login.css"
This because the address /build/login.css must be replaced by /gpexe/public/build/login.css to be usable.
I also try to validate the root htaccess on this website and the address /build/login.css is well rewrited by /gpexe/public/build/login.css.
What am I doing wrong ?

Laravel project in subfolder of public_html gives trouble with .htaccess redirect

I've set up my VPS server and am trying to set up a Laravel project.
I have a /public_html/ folder with an index.html that's shown when visiting the website URL.
I have a laravel project in: /public_html/project_one/
The original index.php is located in /public_html/project_one/public/index.php
I want the website to show to Laravel project_one by default, but since yesterday I literally googled this for 4 hours, I tried every solution on stackoverflow, nothing worked... I think I've tried over 10 versions of .htaccess I could find.
The question:
Does anyone know how to setup the .htaccess inside /public_html/ so it redirects to my Laravel project?
I though I needed to upload my Laravel folder in: /public_html/project_one/ but is there a better location?
I want the main url to show the Laravel project. So www.mainurl.com is Laravel's project_one/public/index.php file. I do not want /project_one/ to be written in the URL!
Just out of curiosity, if I now visit: www.mainurl.com/project_one I get a 403 forbidden.
Failed solutions
In /public_html/ I tried to add .htaccess with:
DirectoryIndex index.php
#Redirect to /project_one/public if you haven't already and the IP is okay
RewriteCond %{REMOTE_ADDR} ^1\.2\.3\.4*
RewriteCond %{REQUEST_URI} !^/project_one/public
RewriteRule ^(/lucaphoto)?(.+) /project_one/public$2 [L]
#if IP does not match and you ARE in the folder, then Redirect to root
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4*
RewriteCond %{REQUEST_URI} ^/project_one/public
RewriteRule .? / [R=301,L]
This gives me something really strange:
On Chrome: it redirects me to www.mainurl.com/project_one -> And then gives me a 403 forbidden error.**
On safari: it redirects me nowhere but gives me this error:
Forbidden. You don't have permission to access / on this server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
Laravel's original .htaccess File
By the way, Laravel has an original .htaccess file at /project_one/public/.htaccess. And it looks like this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# 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}]
</IfModule>
The actual laravel application ( anything but the public folder ) is not supposed to be public and therefore should not be placed inside the public ( public_html ) folder.
I actually tried severel things to get something similar to your setup running. My conclusion was - that only changing the .htaccess file will net e enough to run laravel inside a public folder.
The most easy solution to quickly setup a laravel application is to use a subdomain which directly points to the public folder.
www.mainurl.com /* points to .../public_html/ */
laravel.mainurl.com /* points to .../laravel/public/ OR ( but not good ) */
/* points to .../public_html/my-project/public/ */
What you actually will need to do then is to change the root of your domain / subdomain to point into another folder - no changes to .htaccess are needed then.
Update
If your site is www.example.com and you want your laravel app to show when opening this site you have two options.
Put the content of laravels public folder to public html and change the references to fit the public_html instead of public folder.
If your Filestructure on the server is like .../var/stuff/.../public_html/ then upload everything to ../var/stuff/my-project and then go to your hosters interface and make an internal redirect to the ../var/stuff/my-project/public folder and everything will be fine without chaning anything in your laravel code. ( anything but .env )
So the actual problem is that your domain points to the folder public_html, instead of the public folder of your app. However please dont put your app into public_html directly, put it parallell to it and change where the domain points to.
if you give us some information about your hoster we might can provide a guide

Symfony .htaccess

I configured a test folder for websites in hostgator, so far I have no problems in some flatform like wordpress,magento,joomla, I did not even change any seetings in .htaccess to make it run. Recently, I am working on a symfony2 project and upload my test application in the test folder I created. This is how I create a test folder
mywebsite.com/tests/wordpress_site(no problem)
mywebsite.com/tests/joomla_site(no problem)
mywebsite.com/tests/symfony2_site(403 forbidden error)
In my WAMP, I can accessed my symfony project
localhost/symfony_site/web/
I did not touch the .htaccess since this is just a test site in local machine.
How would you configure a symfony2 project in this setup?
mywebsite.com/tests/symfony_site
It is almost impossible to create clean Urls when installing symfony in subfolder...
With Apache, the better solution is to use a VirtualHost which have tests/symfony_site/web as DocumentRoot, and to use the built-in .htaccess file (which uses url rewriting module, or if it not available, uses a 302 redirection to app.php/)
But If you can't add a virtualHost to your server, it is hard...
An other way is to add a .htaccess at tests/symfony_site and put DirectoryIndex: web/app.php
(https://httpd.apache.org/docs/current/mod/mod_dir.html)
So you can have clean URLs... but be careful with this solution: the urls parsed by the router are relative to your site root (and not to symfony root...) so the router might be lost... (e.g if you have a root named /test you should rename it /tests/symfony_site/test... And it is the same for assets, you have to add the site directory, otherwise they will return a 404 error...
In my case, I just use existing .htaccess in web folder (or I create a new one with a DirectoryIndex Instead), so my app work with URLs like mywebsite.com/tests/symfony_site/web/
I hope this helped,
Vincent
You can try typing the following code into the .htaccess file to the symfony root folder
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(img|files|images|favicon.ico|css|js|robots\.txt)
RewriteRule ^(.*)$ web/$1 [L]
RewriteCond %{HTTP_HOST} host.com
RewriteCond %{REQUEST_URI} !web/
RewriteRule ^(.*)$ web/$1 [L]

remove subdirectory from url, keep root accessible

I just want to remove the subdirectory from the URL but I still want the root directory to be accessible and even fetch the index.php from root when I go directly to the page.
I am currently using the following code:
RewriteCond %{HTTP_HOST} ^(www\.)?website\.com$
RewriteRule !^backup/ /backup%{REQUEST_URI} [L]
But this treats the subdirectory like its root.
Thanks

Resources