SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    htaccess URL Rewrite: example.com/view/unique-name to example.com/unique-name

    I am creating a blog with MVC Pattern. One blog post URL would be example.com/view/unique-name. But I want to rewrite that URL to following format.

    Code:
    example.com/view/unique-name
    to

    Code:
    example.com/unique-name

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,149
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    I don't think this is a job for htaccess rewrite rules. You'll have to do this within your application's router. And you'll want to try this route last, since "unique-name" could be most anything and override your other site URLs.
    "First make it work. Then make it better."

  3. #3
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    I don't think this is a job for htaccess rewrite rules. You'll have to do this within your application's router. And you'll want to try this route last, since "unique-name" could be most anything and override your other site URLs.
    I use Laravel 4. If I set routes like so-

    PHP Code:
    Route::get('{uniqueName}', function()
    {

    });

    Route::get('category/{categoryName}', {
        
    }); 
    When user visit
    Code:
    example.com/category/category-name
    for Category Page, router will thinks "
    Code:
    uniqueName
    " is "category".
    It will work if I set second Route in front of the first. But I have to set other routes for another custom pages.

    Please help me.

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,149
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by heinzawhtet View Post
    If I set routes like so ... When user visit for Category Page, router will thinks "uniqueName" is "category". It will work if I set second Route in front of the first. But I have to set other routes for another custom pages.

    Please help me.
    You'll have to put the "uniqueName" route last. It has to be the last route your application tries. Otherwise it could override any other route.
    "First make it work. Then make it better."

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    heinz,

    It can be done ... provided your CMS can accept the altered URI. Since I'm not aware of any that can, I'd recommend against it.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •