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 9129255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:42:14+00:00 2026-06-17T07:42:14+00:00

In first .htaccess ,I send url to public/index.php : RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s

  • 0

In first .htaccess,I send url to public/index.php:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ public/index.php [NC,L]

And my public/index.php:

<?php
// define root path of the site
if(!defined('ROOT_PATH')){
define('ROOT_PATH','../');
}

require_once ROOT_PATH.'function/my_autoloader.php';

use application\controllers as controllers;

 $uri=strtolower($_SERVER['REQUEST_URI']);
 $actionName='';
 $uriData=array();
 $uriData=preg_split('/[\/\\\]/',$uri );

 $actionName = (!empty($uriData[3])) ? preg_split('/[?].*/', $uriData[3] ): '' ;
 $actionName =$actionName[0];
 $controllerName = (!empty($uriData[2])) ? $uriData[2] : '' ;

 switch ($controllerName) {
case 'manage':
    $controller = new Controllers\manageController($controllerName,$actionName);
    break;
default:
    die('ERROR WE DON\'T HAVE THIS ACTION!');
    exit;
    break;
  }

// function dispatch send url to controller layer 
$controller->dispatch();
?>

I have this directory :

  • application
    • controller
    • models
    • view
  • public
    • css
    • java script
    • index.php
  • .htaccess

I want to have clean URL for example localhost/lib/manage/id/1 instead of localhost/lib/manage?id=1,what should I do ?

  • 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-17T07:42:15+00:00Added an answer on June 17, 2026 at 7:42 am

    Using your current rewrite rules, everything is already redirected to your index.php file. And, as you are already doing, you should parse the URL to find all these URL parameters. This is called routing, and most PHP frameworks do it this way. With some simple parsing, you can transform localhost/lib/manage/id/1 to an array:

    array(
        'controller' => 'manage',
        'id' => 1
    )
    

    We can simply do this, by first splitting the URL on a ‘/’, and then looping over it to find the values:

    $output = array();
    $url = split('/', $_SERVER['REQUEST_URI']);
    // the first part is the controller
    $output['controller'] = array_shift($url);
    
    while (count($url) >= 2) {
        // take the next two elements from the array, and put them in the output
        $key = array_shift($url);
        $value = array_shift($url);
        $output[$key] = $value;
    }
    

    Now the $output array contains a key => value pair like you want to. Though note that the code probably isn’t very safe. It is just to show the concept, not really production-ready code.

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

Sidebar

Related Questions

i have such .htaccess: RewriteEngine On # http://site.com/ru,ua,lt/anything/ RewriteRule ^(ru|ua|lt)/([^/]+)/$ index.php?lang=$1&article_id=$2 # http://site.com/print/ru,ua,lt/anything/ RewriteRule
I have the file structure index.php .htaccess news/index.php news/.htaccess First .htaccess: RewriteEngine On RewriteBase
I have this in my .htaccess: RewriteEngine On RewriteBase / RewriteRule ^url/(.*)$ url.php?url=$1 [L]
Here my .htaccess Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_URI} \/([0-9a-zA-Z]+)$ [NC] RewriteRule ^(.*) image.php?names[]=%1
I've following rules in .htaccess Options +FollowSymlinks RewriteEngine on DirectoryIndex index.php RewriteCond %{ENV:REDIRECT_STATUS} 200
here is the htaccess RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteCond
I want to redirect the following url: http://abc.com/colleges/first.php to http://abc.com/first.php using mod_rewrite and .htaccess
I have a simple .htaccess file: RewriteEngine on RewriteRule ^(.+)-([0-9]+)\.html$ book.php?title=$1&id=$2 RewriteRule ^(.+)\.html$ search.php?search=$1
Could you help me with this htaccess problem of mine? My URL is: mysite.com/blog.php?post=01/01/2012/my-first-post
This is the contents of my .htaccess file: RewriteEngine on RewriteRule ^upload$ upload.php RewriteRule

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.