Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8638171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:39:34+00:00 2026-06-12T10:39:34+00:00

I have urls like this example.com/model/id example.com/image/123 (default rules) I would rewrite it to:

  • 0

I have urls like this

example.com/model/id

example.com/image/123 (default rules)

I would rewrite it to:

example.com/category/123-this_is_encoded_title.html

My image model have following attributes:

  • id
  • title
  • category
    …

I need to add category from model to url.
How can i add category name dynamic to the url?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:39:35+00:00Added an answer on June 12, 2026 at 10:39 am

    it seems that you already using some default CUrlManager rules.

    Add below rule at top of your rule list. (I am assuming your controller id is image)

    '<category:\w+>/<id:\d+>-<title:\w+>.html'=>'image/view',
    

    besides this, you have to change url creation in all places. You have to pass title and category values as the url params.

    ex:

    //Cleanup the title and category
    $model->title = preg_replace("/[^\w+]/", '_', $model->title);
    $model->category = preg_replace("/[^\w+]/", '_', $model->category);
    
    //ex 1:
    $this->redirect(array('view',
             'id'=>$model->id, 
             'title'=>$model->title, 
             'category' => $model->category
    ));
    
    //ex 2:
    echo CHtml::link('Title', array('view',
             'id'=>$data->id,
             'title' => $data->title, 
             'category' => $data->category
     ));
    
    //ex 3:
    $this->createUrl('image/view', array(
             'id'=>$image->id, 
             'title'=>$image->title, 
             'category' => $image->category
    ));
    

    This answer explains what you need to do.

    Please follow the @dInGd0nG suggestion for code re-factoring.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully created rewrite rules to handle URLs like http://example.com/xyz http://example.com/xyz/ http://example.com/xyz/abc http://example.com/xyz/abc/
I have this .htaccess that I've been using to rewrite URLs like these: www.example.com/index.php?page=brand
Currently, I have URLs that look like this: http://www.example.com/user/create http://www.example.com/user/edit/1 But now, I have
I'd like my website to have URLs looking like this: example.com/2010/02/my-first-post I have my
For example, I have an URL that looks for an image like this: http://example.com/img/foo.png
I have requests to UTF-8 urls like this : http://www.example.com:8080/pk/s/151x120/%D8%A2%D9%88%D8%A7%D8%B2-%DA%A9.jpg I stock the result
I would like to have these urls as categories on my page: http://example.com/en/articles //for
I am trying to get my urls to look like this: example.com/posts/id_of_post/title_of_post I have
I have horrible URLs like this: http://example.com/subfolder/index.php?a=1&b=1&token=8d519decbe60db44154b1fbc8c553ac4 I am trying to make it look
I have urls like this: www.wunderwedding.com/weddingvenues/share-weddingvenue/175/beachclub-all-good www.wunderwedding.com/weddingvenues/share-weddingvenue/2567/castle-rock Since these urls no longer exist, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.