Articles tagged with: url
This article shows how we can check if current URL and frontend URl are secure (https) or not in Magento 2.
Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of StoreManagerInterface in the constructor of my module’s block class.
Here are the code snippets to check for different secure URLs in Magento.
Secure URL can be enabled from configuration settings (System -> Configuration -> GENERAL -> Web -> Secure).
Enable Secure URL in Frontend
You have a Magento website with Base URL = http://example.com/
Not working: http://www.example.com/category-one.html (redirecting to homepage)
var current_url = location.href;
Here is another way:-
In your Magento shop URL, if you see “index.php” and wanted to remove it then here is the solution.
– First of all, apache module ‘mod_rewrite‘ should be enabled. Check apache’s httpd.conf file.
– Then login to Magento admin panel
– Go to System -> Configuration -> Web -> Search Engines Optimization -> Use Web Server Rewrites
– Select ‘Yes‘ from the selection list
Suppose you are on a page : http://example.com/category/php/
Now, the base URL or the main URL for the above link is : http://example.com
Similarly, in the case of local machine (localhost),
Suppose you are in the page : http://localhost/myproject/index.php?id=8
Here, the base or main URL is : http://localhost/myproject
PHP, Regular Expression »
Here, I will be showing you a simple and easy one line code to format URL string with PHP. By URL string, I mean the url key in any Search Engine Friendly URL.
I have used preg_replace function to do so.
Breadcrumbs are very useful for user navigation. Breadcrumbs for product page, category page, etc. are created by default Magento code.
The following code will show breadcrumbs created by Magento. You can print the following code anywhere in php or phtml files.