Url hide using codeigniter

后端 未结 2 1789
天命终不由人
天命终不由人 2020-12-12 07:34

I am using codeigniter... I want a clean URL from below URL

  http://localhost:8080/rtvnews/index.php/home/videonews?id=67598/newstitle 

h

相关标签:
2条回答
  • 2020-12-12 08:12

    For hiding index.php from url use following htaccess

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    More on htaccess

    URI Routing

    Considering newstitle as unique:

    Go to your route.php file (application/config/routes.php) . Add new route rule as below

    $route['rtvnews/news/(:any)'] = 'home/videonews/$1';
    

    in your view file

    <a href="<?php echo base_url()."rtvnews/new/".$newstitle; ?>" > News Title</a>
    

    so your url became as below

    http://localhost:8080/rtvnews/news/uniquenewstitle  
    

    Your request go to home/vidonews function where you can get your newstitle as parameter.

    In your controller.php function will be like

    function vidonews($newsTitle){}
    

    Considering id as unique :

    Add new route rule as below

    $route['rtvnews/news/(:num)'] = 'home/videonews/$1';
    

    In view.php file

    <a href="<?php echo base_url()."rtvnews/new/".$newsId; ?>" > News Title</a>
    

    so your url became as below

    http://localhost:8080/rtvnews/news/newsId
    

    Now your request go to home/vidonews function where you can get your newsId as parameter. In your controller.php function will be like

    function vidonews($newsId){}
    
    0 讨论(0)
  • 2020-12-12 08:28

    Follow the steps below

    Step 1: .htaccess (the one which is at root folder)

    Options All -Indexes
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    Step 2: routes.php add the code below

    $route['rtvnews/news/newstitle'] = 'Your controller/method']; //Just a syntax to change the route in codeigniter. You can change the url as per you want.
    
    0 讨论(0)
提交回复
热议问题