I want to create a url like `localhost/magento/{frontname}/profile/id/5'

so, i have created a controller file profile.php

namespace Learning\HelloPage\Controller;
use Magento\Framework\Controller\ResultFactory;
class Profile extends \Magento\Framework\App\Action\Action

    public function __construct(
       \Magento\Framework\App\Action\Context $context)

     * View  page action
     * @return \Magento\Framework\Controller\ResultInterface

    public function execute()
       $seller_id = $this->getRequest()->getParam('id');

       $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);

       return $resultPage;

this is i have done so far and if i run this url : localhost/magento/{frontname}/profile/id/5 it takes me to 404 page please suggest a solution.


In order to create URL like localhost/magento/{frontname}/profile/id/5, you need to define the route front name in app/code/Learning/HelloPage/etc/frontend/routes.xml file.

Below is the syntax:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="viewfile" frontName="viewfile">
            <module name="Learning_HelloPage" />

Where you can define the front name under frontName parameter.

Note: I assume that you have already created module's basic skeleton, i.e.

  • app/code/Learning/HelloPage/etc/module.xml
  • app/code/Learning/HelloPage/registration.php
  • hi i have created the routes.xml file also but tell me how can i run this localhost/magento/viewfile/profile/id/5 url – Jay Kapoor Oct 23 '17 at 12:26
  • Please share the steps which you have done so far? – Mohit Kumar Arora Oct 23 '17 at 12:27
  • I think you have not run command: php bin/magento setup:upgrade – Mohit Kumar Arora Oct 23 '17 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.