Magento 2.2.5 redirect from sub to root - magento2.2

I am new to Magento. Successfully installed/implemented Magento 2.2.5. However, I installed Magento as subfolder in root. And my cart shows as mydomainname.example/magento. I want to change it so public does not see 'magento' in my URL. I found several posts regarding it.e.g. How To Direct Magento installation path in subfolder to main domain name. My challenge is that Magento 2.2.5 index.php file does not have any code line 45 that I can edit.

You can try to move all folders from Magento to the root.
But if you need subfolders anyway you can use one of this solutions:
1) Open apache or nginx settings and specify the Magento folder as the "root directory" of your website.
2) You can also create file at the root, name it index.php and the content will be <?php require __DIR__ . '/magento/index.php'; ?>

First thing the referenced solution is a Magento 1, it's a very different framework from Magento 2!
In your case I think you need to edit the .htaccess in the parent folder like in this post
# Mod Rewrite
Options +FollowSymLinks #Include this line if you are using Godaddy hosting
RewriteEngine On
RewriteCond %{REQUEST_URI} !(.*)magento
RewriteRule ^(.*)$ magento/$1 [L]
at last, I recommend https://magento.stackexchange.com/ for the magento related questions as it's dedicated to Magento

Related

Laravel 8 project deploy to shared hosting - security issues and public_html folder

I was able to deploy my laravel 8 application as and addon domain on inmotion shared hosting based on the following article
https://medium.com/backenders-club/how-to-host-a-laravel-project-on-a-shared-hosting-via-cpanel-d955d32c528e
However, there are security issues with this as I can type mysite.com/.env and the file contents is listed in the browser showing the passwords.
I've tried many options to place the public folder of my laravel app into a public_html/public folder and none have worked for me. Anyone also getting this problem?
Addon domain Document root - /public_html/public
Laravel 8 application - /mysite.com (public folder contents moved to public_html/public)
Inside the public_html/public folder, the index.php file modified as follows:
require __DIR__.'/../../mysite.com/vendor/autoload.php';
$app = require_once __DIR__.'/../../mysite.com/bootstrap/app.php';
In browser I get 'No input file specified.'
bad practice if you try to move files inside public folder to root directory , any one can view the files that exist in the root ,
my advice to you ,return your files to the public folder and use one solution from this :-
first , you can make change the domain document root to public path
second you can create .htaccess file in the root folder and contain this code :-
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
i prefer the first solution.

Magento 2.4.2 - Installing a Fresh Install into a Subdirectory - Does not Work?

It appears that it is not currently possible to install the latest Magento Community Edition within a subdirectory (or there are steps required, which are not in the Documentation that I can find?) with a fresh install.
I have tested this 3-4 times in the last 2 days. If you install it into the root it works as anticipated, if you install it in a subdirectory - the install says it has worked but the index.php is missing and the .htaccess file is still the default one that comes with the composer project setup.
This works for root folder:
--base-url="http://www.fieldhockey.co"
This does not work for the subdirectory:
base-url="http://www.fieldhockey.co/store"
All the other setup:install parameters are the same in both attempts.
I found little about this issue so that is why I have created this - perhaps someone can try this out on a different setup than mine:
Cent OS 7.9 (v92.0.10)
PHP 7.3.27
Apache 2.4.46
My Question(s)
So my questions on the back of this issue - how do I then move the installation to a subdirectory? And is it correct that there is no index.php - even when the install works in the root and the site displays?
Updating the base_url in the database to include it and moving all files into that directory and then clearing the cache & reindexing does not work?
Just out of curiosity - I took the default index.php script and .htaccess from a site I setup on 2.4.1 back in November... and now my store works in the subdirectory after moving the files from the root directory (but the admin cannot load any CSS etc or 2FA so I cannot login).
UPDATE - 19/02/2021 - 13:24pm (GMT)
I think the issue is the install itself not the subdirectory - to test this theory I will install 2.4.1 and see if I get better results.
UPDATE - 19/02/2021 - 15:10pm (GMT)
2.4.1 successfully installed in root, both front end and backend are working. I will now attempt to move the site into the store directory manually. If that fails I will attempt to install it to the subdirectory directly.
UPDATE - 19/02/2021 - 15:52pm (GMT)
Moving worked thou came across an issue I hadn't seen mentioned before regarding the JS/CSS breaking when relocating to a new directory. There is a .htaccess file in the /pub/static/ directory which doesn't seem to be created when a new static folder is generated - so you probably shouldn't rename the /pub/static/ directory to force it to be regenerated.Magento 2.4.1 - Moved site to a subdirectory - CSS & JS Broken - cleared Cache still broken [SOLVED]
SO ANYONE ANY IDEAS?
At this stage I cannot understand why 2.4.1 is working but 2.4.2 isn't - I cannot see any mention in the release notes pertaining to a non optional module or version of anything significant (PHP, Apache, ElasticSearch, Composer etc)
I can keep it on 2.4.1 but it isn't really the point, I should be able to use 2.4.2 is I want to and have the means to do so?
I hope this helps anyone else trying to do this, I will work with 2.4.1 for a few weeks and then try to upgrade again.
I managed to make it work, a bit hacky though.
I'll take my example, I want to do : example.com/nl.
I created a folder "nl" in the root folder. I added a .htaccess in it with the content :
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/pub/
RewriteCond %{REQUEST_URI} !^/setup/
RewriteCond %{REQUEST_URI} !^/update/
RewriteCond %{REQUEST_URI} !^/dev/
RewriteRule .* /pub/nl/$0 [L]
DirectoryIndex index.php
Then I created a "nl" folder in the "pub" folder.
This folder contains 2 files : .htaccess, index.php.
.htaccess is a copy/paste of the "pub" one, I just added :
SetEnv MAGE_RUN_CODE "nl_nl"
It's not mandatory you can do set your store via the index.php, it's explained in it by Magento.
index.php is a copy/paste of the "pub" one.
I just added another "../" in the require.
require __DIR__ . '/../../app/bootstrap.php';
In admin :
Url base : example.com/
Url base link : example.com/nl/
My vhost point to the root:
ServerName example.com
ServerAlias example.com
My main issue there was that the site was accessible but Magento had trouble to rewrite and every page was in 404. Here comes the hack.
In the "pub/index.php" file I added the following line before Magento instantiates everything:
$_SERVER['REQUEST_URI'] = str_replace('/nl/', '/', $_SERVER['REQUEST_URI']);
Looks like it works fine but I didn't push the tests further.
In 2.4.2, Magento moved the index.php to the /pub/ folder for security purposes.
I'm trying like you to create a subdirectory : example.com/nl
I moved my "nl" folder in /pub/ and changed the require from
require __DIR__ . '/../app/bootstrap.php';
to
require __DIR__ . '/../../app/bootstrap.php';
In admin, urls for secure and non-secure :
Base Url is https://example.com/nl/
Base Link Url is https://example.com/nl/
Sadly when I go to https://example.com/nl/ the site display a 404 even though it displays the correct theme design, the correct translations etc...
Tomorrow I'll try again and keep you updated if I succeed.
Maybe this already give you a hint though...
After Installed magento 2.4 version your localhost support with /pub directory like {localhostname}/pub/index.php
We can access without pub directory follow below steps
1. Copy .httaccess file from pub folder and override it to root .htaccess file
2. Upload pub/index.php file to root magento directory
3. Add below code in app/etc/env.php file
'system' => [
'default' => [
'web' => [
'unsecure' => [
'base_media_url' => '{{secure_base_url}}pub/media/',
'base_static_url' => '{{secure_base_url}}pub/static/'
],
'secure' => [
'base_media_url' => '{{secure_base_url}}pub/media/',
'base_static_url' => '{{secure_base_url}}pub/static/'
]
]
]
],

Magento Redirect base url

I have all my folders and files in www.mysite.com/magento/ and my home page base url is www.mysite.com/magento/. I need to change this url to only www.mysite.com and if possible I don't wanna move my files from /magento/ to the back folder.
If I use System - Configuration - Web from my magento-admin-panel, it doesn't work and I can't connect to panel.
You should be able to accomplish that using .htaccess and RewriteBase.
Here's commented out example in Magento .htaccess sample:
############################################
## you can put here your magento root folder
## path relative to web root
RewriteBase /magento/
That should do the trick in your case.
You can read more about RewriteBase here: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#page-header
Edit: In the web root, you'll need some sort of rewrite to Magento root directory:
RewriteEngine on
RewriteCond %{REQUEST_URI} !magento/
RewriteRule (.*) /magento/$1 [L]
Keep in mind that there are all just untested examples that should point you in the right direction. :)
Cheers.

How to setup laravel in this url format http://ip-address/~username

I had setup Laravel projects before but this is my first time setting it up on this url format: http://ip-address/~username.
When I first visited the url, it just shows the directory listing so I tried accessing it by appending /public in the url and it works. However all the other links have /public on it and leads to a 404 error.
This is the current directory structure:
inside public_html
- app
- bootstrap
- config
- database
- public
- other folders
- htaccess
- other files
I tried putting an htaccess file in the project root folder.
<IfModule mod_rewrite.c>
Options -Indexes
RewriteEngine On
RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>
However it still doesn't work and I don't know what to do anymore. If you have been in this kind of situation before, please help me. Thank you in advance.
You'll need to set your WebServer's document root to the public directory, that way it looks in the public and you wont have to append your url with public all the time.
Either that or you'll have to move your index.php out of the public directory and put it inside the root directory your web server is currently set as, but I would recommend you do the first option.

Transferring codeigniter HMVC project from localhost to live server

I made a web application on codeigniter HMVC. I tested it on local server and the following link works perfectly fine by giving me a login form, the link : http://localhost/bird_vision/users/login, where my directory structure goes like this bird_vision/application/modules/users/users.php (users->module's name, users.php->controller's name). Now I posted the whole "bird_vision" folder to web using filezilla.
- changed the base_url in config.php file to domain_name
- Made some changes in .htaccess file
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$10 [L,QSA]
</IfModule>
Now when I write bird_vision.se/bird_vision/users/login in my address bar it gives me 404 page not found. Although when I when type birdvision.se/bird_vision/welcome it gives me welcome to codeigniter page.
Please I need help as my all hardwork making this project is at stake. Thanks in advance.
I figured the problem was not with HMVC but was with codeigniter version 3.0. When it comes to unix(which was the operating system running on my server), it is case sensitive. So when I tried to access the controller it could'nt find the file because of case sensitivity and a 404 popped out everytime.
My folder structure before was something like :
-application
-->modules
--->users
---->controllers
----->users.php
And the link on which I was getting 404 was www.example.com/users/login
where "users" in the link is controller's name within the "controllers" folder under "modules" folder in my case named as users.php and "login" is the function inside the controller.
All I had to do was to change the case of the first letter of my module and controller name. Now my directory looks like
-application
-->modules
--->Users
---->controllers
----->Users.php
note : capitalized "U" in Users module and Users controller.
And the the url I used to access the users controller was : www.example.com/Users/login
And I was back in business.

Resources