I'm working on an microservice based arhitecture with Lumen.
The local environement is working fine, but the production server needs adjustments, because it can't have the same link structure, and I want the code to be the same in every env.
In the local env I created virtual hosts for every microservice, like for e.g. books.xyz, and authors.xyz
that point to the /public folder, so link structure DOESN'T contain public.
On live, it is hosted like server .servername.com/books and beta.servername.com/authors.
I have started developing an admin panel with lumen ( /admin ) but the problem is that the link structure is too different, and doesn't work on production. ( css/js assets get 404'd etc.)
How can I remove the /public in the production URL?
I don't want to move everything from public folder into root, because of security reasons!
I have tried creating a .htaccess file on the root, and the following, but none of them worked :
# <IfModule mod_rewrite.c>
# RewriteEngine On
# RewriteCond %{REQUEST_URI} !^/books/public/
# RewriteRule ^(.*)$ /public/$1 [L,QSA]
# RewriteRule ^game/(.*)$ /books/public/$1 [L,QSA]
# </IfModule>
or
# <IfModule mod_rewrite.c>
# RewriteEngine On
# RewriteRule ^(.*)$ books/public/$1 [L]
# </IfModule>
or
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ books/public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
Related
Hello my fellow developers,
i need to change my document root some specific folder which holds the source code of my laravel project on a shared hosting, since my hosting plan dont let me change default document root so i cannot change my default index so i want to have to redirect it using .htaccess
for far i have been able to internally redirect with the following code
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*)$ master/project/public/index.php
doing this i am able to redirect to desired folder, but for some reason it is not working for assets, i keep getting 404 on all the assets
master/project/public/css/[all styles]
master/project/public/js/[all scritps]
master/project/public/images/[all pictures]
master/project/public/fonts/[all fonts]
how can i achieve this without having to change urls,
internal redirect is working but i cannot figure out why all of my assets are returning 404
Try this
i m using shared hosting and this i m using for redirect asset to public dir
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
#all request to public dir
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
To redirect all request to public
#all request to public dir
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
so i found solution to my problem,
this solution is what i ended up with.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !master/project/public/
RewriteRule (.*) /master/project/public/$1 [L]
this way you can change the default root of the your hosting using .htaccess file. hopefully it is helpful for everybody new to .htaccess
I have a Laravel app that resides in a folder in a Wordpress based website. Name of folder is "artists". It is a database app to list local artists.
I need help rewriting url using .htaccess
Current URL
https://example.ca/artists/artists/name-of-artist
Desired URL
https://example.ca/artists/name-of-artist
Any help would be greatly appreciated. Thanks !
Here is the current .htaccess in the root folder of the Laravel app (artists)
#<IfModule mod_rewrite.c>
#RewriteEngine On
#RewriteRule ^(.*)$ public/$1 [L]
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
The correct command you are advised to use is "RedirectMatch 301". Add the following line into ".htaccess" inside public folder of Laravel:
RewriteEngine On
# Custom Rule START #
RedirectMatch 301 ^/artists/artists/(.*)$ /artists/$1
# Custom Rule END #
I want to edit my .htaccess file so all the requests will be encrypted (I have SSL certificate active). I'm trying to run a Laravel app, which has Index file in public folder and I want to let user access my page without the /public/ part in URL.
So far, I managed to do this:
This part let me access the page without the /public/ part.
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
This part redirects all data to HTTPS:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.club/public_html/1 [R,L]
The question is, how do I merge these two together? They work separately, but not if I put this together in .htaccess file.
.htaccess file is located in public_html which is located in root folder. Laravel folders (incluing public) are located in this folder.
Try this
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I'm using Laravel 5.5.
Laravel has couple of .htaccess and in my case I'm working with .htaccess on root and inside the public folder.
All this time I was using this code in root .htaccess to setup the public folder:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
and my website is loading when I enter the homepage.
After that, I wanted to force redirect all the pages using https. So, first when I try to put this code inside the root .htaccess it doesn't do anything. It keeps loading with http.
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Well, it makes sense, because when I setup the public folder, I have to put the redirect inside the .htaccess that is located inside the public folder.
OK, so I've tried like this now:
The root .htaccess:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
The public .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This combination works. It does redirects to https.
But, there's one issue now. When I enter the homepage or if I open the website from the search results, the URL looks like this:
https://mywebsite.com/public/en
When I enter the other pages, I don't have issue related with the "public" path in the URL. So, let's say I want to open the contact page, the URL is https://mywebsite.com/en/contact. That's fine.
How can I avoid that "public" in my URL when I enter the homepage?
This should remove public from the url.
RewriteRule ^(.*)$ public/$1 [L]
I am not sure if this should go above
# Handle Front Controller...
or within it? Maybe try either one and see if either work?
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1 [L]
RewriteRule ^ index.php [L]
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
source
Please find my Laravel website URL below: www.webrox.ae
This website problem is that.. It opens /index.php and for all menu items like portfolio or hire us etc it it opens name/oservices/public/portfolio.. Something like this,....
Below is my htaccess file
Please Guide
#Alternate default index page
DirectoryIndex www.webrox.ae/index.php
# BlueHost.com
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
# Change 'subdirectory' to be the directory you will use for your main domain.
# Don't change the following two lines.
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?webrox.ae$
RewriteCond %{REQUEST_URI} !^/oservice/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /oservice/public/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?webrox.ae$
RewriteRule ^(/)?$ webrox.ae/index.php [L]
RewriteCond %{HTTP_HOST} ^www\.webrox\.ae$
RewriteRule ^/?$ "http\:\/\/webrox\.ae\/" [R=301,L]
Thanks
Change the line from
RewriteCond %{REQUEST_URI} !^/oservice/public/
RewriteRule ^(/)?$ webrox.ae/index.php [L]
to
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^(/)?$ webrox.ae [L]
And add the line
RewriteRule ^ index.php [L]