120

In magento 2. If you want to get Base url ,then you can try below code: /** * @var \Magento\Store\Model\StoreManagerInterface $this->_storeManager */ $this->_storeManager->getStore()->getBaseUrl(); Where $this->_storeManager instance of \Magento\Store\Model\StoreManagerInterface this above code will give you result http://www.example....


64

Symptom: I changed Base Urls and now my website is inaccessible or I moved everything to a new server, didn't change the base_url and my website is inaccessible. How to change or restore base_url settings with phpMyAdmin Instructions are for a simple "one store" website where the "default store view" is set to inherit its setup from the "default config". ...


44

Simply use this command with you are using a class that extends \Magento\Framework\View\Element\Template. $this->getBaseUrl() If not, use this: $this->_storeManager->getStore()->getBaseUrl() Or if you are using it in a PHTML template use: $block->getBaseUrl()


40

First look at getBaseUrl() at Mage.php public static function getBaseUrl($type = Mage_Core_Model_Store::URL_TYPE_LINK, $secure = null) { return self::app()->getStore()->getBaseUrl($type, $secure); } In a simple word we can say: Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) indicated Your Magento Site Url from this url ...


37

You can add current store URL in static block. {{store url=""}} If you wanto add store url with category URL. {{store url="category-url"}}


18

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 have to pass your frontname from routes.xml file instead of module name(namespace_module) You can lookup your routes.xml file from app/code/Namespace/Module/...


16

The default answer is, set the unsecure base url to https:// depending on your setup this already is enough for a redirect if users try to use http:// Maybe a redirect on webserver level is better, as it avoids requests going through php first. And if you want the real perfectly secure solution, you should add your website on https://hstspreload.appspot....


15

Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_SECURE_URL); I mention this because no one else has, but I prefer using Mage::getUrl or Mage::getBaseUrl. Both of those automatically detect if the page is already secure when you do not specify it.


14

In Magneto2: This is way to get Url link in PHTML file: echo $this->getUrl('about-us') I hope it will work for you


13

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 commands: Set Unsecure URL bin/magento setup:store-config:set --base-url="http://www.magento2.com/" Set Secure URL bin/magento setup:store-config:set --base-url-...


13

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 “Yes.” 4 When complete, tap Save Config Hope this will help you.


12

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 $_storeManager; public function __construct( ... \Magento\Store\Model\StoreManagerInterface $storeManager ) { $this->_storeManager = $...


11

as @Aphroz said, you can use Mage::getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB, true ); in order to retrieve secure base url. This returns secure url because we have specified it through second parameter true. Here first parameter is specified as Mage_Core_Model_Store::URL_TYPE_WEB. This means the method returns value correspond to this system ...


10

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 below command. sudo rm -rf var/cache var/generation var/page_cache Ensure you have updated your virtual host settings according to the new URL. Once you set the ...


9

I believe this was the same cache poisoning attack as seen here: http://seclists.org/fulldisclosure/2011/Feb/123 In short, if you use the default virtual host and {{base_url}} as your site URL, an attacker can send requests to your site with the Host header set to evilsite.com. If they do this and a cache miss happens, then the generated cache would ...


8

You can use a a model to generate the comment for a config field: Something like this: <comment> <model>ultimate_shipper/adminhtml_allowedmethods_comment</model> </comment> then you need to create the file: Ultimate/Shipper/Model/Adminhtml/Allowedmethods/Comment.php with this content: <?php class ...


7

My guess is you are executing this code in the sql directory. This one is only for altering the database structure. As you suspected not everything is initialised when the sql setup scripts are executed. To work with data, put your code in the data directory. The output of sql/emzee_exampleextension_setup/install-0.0.1.php: NULL string(10) "index.php/" ...


7

Inside controller you can get this by following way $this->getUrl($route, $params) Another way Create \Magento\Backend\Helper\Data object by objectManager. $this->_helper->getUrl($route, $params) $this->_helper is Magento\Backend\Helper\Data


7

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 ^(.*)home$ http://www.domain.com/$1 [R=301,L] or you can do this by Go to System->Configuration->Web->Url Options and set the field Auto-redirect to Base ...


6

Go to System->Configuration->web open unsecure,secure Tabs Put your site's URL in those tabs. See the image below.


6

Try it like this: $storeId = 1; //the store you need the base url: $homeUrl = Mage::getUrl('', array('_store' => $storeId)); For a product url do this: $url = Mage::getModel('catalog/product')->setStoreId($storeId)->load(1)->getProductUrl(); $storeId is the same as above.


6

Found the solution. Accessed the core_config_data table via phpMyAdmin, and removed the value of web/cookie/cookie_domain and set web/cookie/cookie_httponly to 0. Cleared the cache by removing the files in var/cache. Site's back up :)


6

If you just want to get a URL from your Magento install's root directory you can just use getUrl. It inherits from the AbstractBlock class (Magento\Framework\View\Element\AbstractBlock) so you are able to use it an any of your blocks. Here is an example $this->getUrl('pub/media/video/', ['_secure' => $this->getRequest()->isSecure()]).$fileName ...


6

inject store manager and simply get base url public $_storeManager; public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, ..... ) { ... $this->_storeManager=$storeManager; } $this->_storeManager->getStore()->getBaseUrl(); Note: don't create object manager always inject


6

Just figured it out! Apparently Chrome doesn't play nice with cookies when they are single-level domain (like localhost). Changing my environment to localhost.dev and mapping it in my hosts-file and changing the configuration of Magento 2 solved this problem! I'll leave this answer here to save other people hours of debugging and mashing their head on their ...


6

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 / General / Single-Store Mode / Enable Single-Store Mode = Yes). In this case, if you set the Base URL value using Magento CLI, it will be saved with 'websites' scope. ...


6

You can get the default website id like this: $websites = Mage::getModel('core/website')->getCollection()->addFieldToFilter('is_default', 1); $website = $websites->getFirstItem(); $websiteId = $website->getId(); $websiteCode = $website->getCode(); and you can get the base url like this: $url = Mage::getConfig()->getNode('web/unsecure/...


5

The redirection back to the login page (with no error) usually means that the session cookie saved was by the wrong domain path. Try setting your Cookie Domain and make sure that HTTP Only is disabled in Magento. Do the following: Go to System > Configuration > Web Expand Session Cookie Management Set the following: Cookie Path: / Cookie Domain: ...


5

Below URL Access list Get URLs in CMS pages or static blocks Base URL: {{base url=''}} Store URL: {{store url='test.html'}} also only store URL {{store url=""}} Media URL: only get media URL {{media url=''}} if you get some folder path {{media url='imagefolder/imagename.jpg'}} Skin URL: {skin url='images/imagename.jpg'}} only get skin URL {...


5

I have found solution. Bellow is my code. <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $conf = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue("web/unsecure/base_url");?> Thanks.


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