Skip to main content
53 votes
Accepted

Magento 2 get base url (current store) in admin static block/page?

You can add current store URL in static block. {{store url=""}} If you wanto add store url with category URL. {{store url="category-url"}}
Suresh Chikani's user avatar
29 votes
Accepted

How to get the base url from a JS file?

define([ 'jquery', 'mage/url' ], function ($,url) { var linkUrl = url.build('frontname/regions/index'); console.log(linkUrl); }); Where frontname is your routes.xml file frontname. You ...
Rakesh Jesadiya's user avatar
23 votes

How do I fix my Base URLs so I can access my Magento site?

In Magento2, there is also a way to do this directly via Magento using below commands rather than having to go through SQL which i find a bit quicker. Within Magento’s root directory run below ...
harri's user avatar
  • 5,495
19 votes
Accepted

remove index.php from getBaseUrl()

URL rewrites will remove index.php from url How to enable URL rewrites? 1 Stores > Configuration > Web 2 expand the Search Engine Optimization section 3 set Use Web Server Rewrites to “...
Denish Vachhani's user avatar
16 votes

How to get the base url from a JS file?

You can retrieve the baseUrl from the global JS variable BASE_URL, and use it by setting the baseUrl from the mage/url module. define([ 'jquery', 'mage/url' ], function ($, url) { url....
Rick Daalhuizen's user avatar
15 votes

How to get Magento 2 base URL?

In Magneto2: This is way to get Url link in PHTML file: echo $this->getUrl('about-us') I hope it will work for you
Chandra Prakash Gupta's user avatar
15 votes
Accepted

magento2: getBaseUrl() in helper class?

Based on the duplicate question, I'm just going to explain how to do it in an helper/controller First you have to inject the Magento\Store\Model\StoreManagerInterface in your constructor: protected $...
Raphael at Digital Pianism's user avatar
15 votes
Accepted

Magento2 - Use placeholder {{base_url}} in multistore

I found the Solution. Just end your url with a /(Slash).
Anees's user avatar
  • 634
14 votes

Base Url Change Magento2.1

First update both the web/unsecure/base_url and web/secure/base_url URLs in core_config_data to http://www.domain2.net/ in your database, you can use the above query. Then, clear the cache by the ...
Sukeshini's user avatar
  • 9,965
11 votes

Magento 2 get base url (current store) in admin static block/page?

You can add store URL in static block: <a href="{{store direct_url='identifier'}}">Your link</a>
SIDDHANT JAIN's user avatar
9 votes

Configure baseurl in Magento 2 env.php or config.php?

Yes, you can do that from Magento 2.2 in following way. Put this code in env.php file <?php return [ 'system' => [ 'default' => [ 'system' => [ '...
Sasa Jovanovic's user avatar
8 votes
Accepted

How to get admin side base url in magento 2?

You can use following code directly in your phtml file to get admin URL. echo $this->helper('Magento\Backend\Helper\Data')->getHomePageUrl();
Dinesh Yadav's user avatar
  • 6,455
7 votes

How to get Magento 2 base URL?

inject store manager and simply get base url public $_storeManager; public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, ..... ) { ... ...
Surendra Kumar Ahir's user avatar
7 votes
Accepted

Magento 2: get store url without store code [SOLVED]

I have found solution. Bellow is my code. <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $conf = $objectManager->get('Magento\Framework\App\Config\...
Jalpesh Patel's user avatar
6 votes
Accepted

How to get base url of default website?

You can get the default website id like this: $websites = Mage::getModel('core/website')->getCollection()->addFieldToFilter('is_default', 1); $website = $websites->getFirstItem(); $...
Marius's user avatar
  • 198k
6 votes
Accepted

How the "magento setup:store-config:set --base-url" command exactly works?

I can guess it have something to do with multi-store configurations, but I still do not understand how.. It seems that you turn on 'Enable Single-Store Mode' option (Stores / Configuration / ...
Danil's user avatar
  • 371
6 votes

Magento2: Remove home after base url

You can do it using htaccess file . In htacess file find: Options +FollowSymLinks RewriteEngine on Then Put the below code in htaccess file RewriteCond %{THE_REQUEST} ^.*/home RewriteRule ^(.*)...
surbhi agr's user avatar
5 votes

Force HTTPS on all pages in the frontend, not just Checkout/Account

For anyone stumbling across this (like I did) Don't use htaccess. Under admin go Stores -> General -> Web and change -> Use Secure URLs on Storefront -> Yes and Use Secure URLs in Admin -&...
Andrew's user avatar
  • 59
5 votes
Accepted

How to get store information (e.g Store Base Url) of another store in a multi-store setup for Magento 2

In your custom block, the below code will get the store Base Url by using store id: namespace Vendor\Module\Block; class Store extends \Magento\Framework\View\Element\Template { public function ...
Khoa TruongDinh's user avatar
4 votes

How to get admin side base url in magento 2?

$this->helper('Magento\Backend\Helper\Data')->getAreaFrontName(); // admin_7asd32 $this->helper('Magento\Backend\Helper\Data')->getHomePageUrl(); // http://magento.com/admin/admin Note ...
Yamen Ashraf's user avatar
4 votes

How to get the base url from a JS file?

I'am not sure what you are doing but i think you should pass url to js(widget). Url is parameter of js widget Put script below to your template where you want <script type="text/x-magento-init"&...
mrtuvn's user avatar
  • 3,283
4 votes
Accepted

Programmatically change base url of store

protected $config; protected $storeManager; public function __construct( ... \Magento\Config\Model\ResourceModel\Config $config, \Magento\Store\Model\StoreManagerInterface $storeManager, ...
Keyur Shah's user avatar
  • 18.1k
4 votes

How to get base url in Unit Test?

I think you have to look into the core Magento unit test code how they use and get base URL. I am not sure about this is what I shared is exactly you want, but I think it will help you. Look into ...
Chirag Patel's user avatar
  • 6,136
3 votes
Accepted

How to define/change baseurl in config for magento 2.0?

You can override the base url values per environment using environment variables. Edit the app/etc/env.php file and include the following at the top of the file: $_ENV['...
Andy's user avatar
  • 151
3 votes

inject config programmatically

in app/etc/local.xml for each host put the following: <stores> <default> <web> <unsecure> <base_url>http://...
Yehuda Schwartz's user avatar
3 votes

Magento 2 get admin base url in custom js

You can pass url for ajax request as argument when initializing your component. view.phtml <div data-mage-init='{"Vendor_Name/js/you/component": {"url": "<?php echo $block->getUrl('your/...
Max's user avatar
  • 4,054
3 votes

How to get the base url from a JS file?

Add this code in phtml file : <input type="hidden" value="<?php echo $this->getUrl(); ?>" id="baseUrl"/> Now you can use this base url in js file by id : $("#baseUrl").val(); This ...
Rohan Hapani's user avatar
  • 17.4k
3 votes

SecurityError: Permission denied to access property "tinymce" on cross-origin object

I found the answer here: https://magento.stackexchange.com/a/61593/761 The Unsecure URL settings configured in the default config (top left) in the admin section. Are global – they affect all the ...
Pascut's user avatar
  • 329
3 votes

Magento 2: Get base URL in web template

=> Set URL in the JS file : First of all, Add mage/url to the list of dependencies. Then, Add the following function to the knockout JS file: getBaseUrl: function() { return url.build('<...
Rohan Hapani's user avatar
  • 17.4k
3 votes
Accepted

Magento 2 - How to get Base URL in cronjob

I think before calling getBaseUrl() you need to set your current store then you can get correct URL. $this->storeManager->setCurrentStore($storeId); Where $storeId is your store Id which you ...
Keyur Shah's user avatar
  • 18.1k

Only top scored, non community-wiki answers of a minimum length are eligible