I have an page url of magento site.

my question is : how can i check the page url is category page or cms page or other page?

for example:

page URL is : http://example.com/craft.html(category page) or http://example.com/terms-policy(cms page)

i want to check page url is category page or cms page.


  • $this->getRequest()->getControllerName() == 'cms' is CMS page Dec 16, 2017 at 12:05
  • blog.chapagain.com.np/… Dec 16, 2017 at 12:06
  • 1
    hi @MineshPatel no i don't want this. your code match current page controller name with "cms". i edit my question with an example please see.
    – pooja
    Dec 16, 2017 at 12:12
  • You need to check in Table core_url_rewrite and cms_page for this Dec 16, 2017 at 12:58

1 Answer 1


I think the answer given by Minesh in comments are partially correct. If you are trying to check it in your template file you can use below codes to check whether you are in category page, cms page or product page.

To check if you are in category page:

if (Mage::registry('current_category'))
  // category page

To check if it is a cms page:

if(Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms')
  // CMS page

To check if it is a product page:

  // Product detail page


From your comment, below code will let you know the last page url is either cms page, or category or product.

$lastUrl = Mage::getSingleton('core/session')->getLastUrl();
    if (preg_match("#cms/index/index#", $lastUrl)) {
        return "Last page was:<br>Home page<br/>url: ".$lastUrl;
    elseif(preg_match("#catalog/category/view#", $lastUrl)) {
        return "Last page was:<br>Category page<br/>url: ".$lastUrl;
    elseif (preg_match("#catalog/product/view#", $lastUrl)) {
        return "Last page was:<br>Product detail page<br/>url: ".$lastUrl;
        return "Last page was:<br>Unknown page<br/>url: ".$lastUrl;

I hope this will help. If it works for you pleae don't forget to accept and vote the answer. This will help others too.

Happy Coding!!

  • 1
    your answer is correct @aton1004 but i need to get the page type on another page. for example: if i am on category page and its previous page is home page then i need to show home page type (cms) show on category page. inshort, i need to know the previous page type. is it cms or category.
    – pooja
    Dec 18, 2017 at 7:00
  • @pooja from your question it was not clear of your requirement. Please check the code from edited section to find your answer. if it helps don't forget to accept and vote up the answer. Cheers!! Dec 18, 2017 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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