Answers to About URL that doesn't really exist ( 3 )

  1. 2017-01-06 20:01

    You can create an .htaccess file that routes ALL requests through a single PHP file and then use the logic in that PHP file to determine whether the url exists or not. For example, you could use my CodeIgniter .htaccess file:

    RewriteCond $1 !^(index\.php|images|css|fonts|js|robots\.txt|test)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    This lets you still specify images, css, js, etc. that doesn't get remapped but any urls that don't start with those strings will be routed to index.php. Within index.php, you can inspect the query string to determine how to handle the urls and decide if they exist or not.

    // code in index.php, modify to suit
    switch ($_SERVER["PATH_INFO") { // you might also check out REQUEST_URI
      case "foo":
        // do blah blah blah
        break;
      case "bar":
        // do other blah blah blah
        break;
      default:
        header("HTTP/1.0 404 Not Found");
        echo "Sorry but that page was not found";
    }
    
  2. 2017-01-06 20:01

    You can use URL rewriting by editing .htaccess file. If .htaccess is not there then you can create one on project root directory.

    RewriteEngine on
    RewriteRule ^/?Some-text-goes-here/([0-9]+)$ /picture.php?id=$1
    

    the above will convert url.com/picture.php?id=51 to picture.php/Some-text-goes-here/51

    In same way you can use yours strtagy.

  3. 2017-01-06 21:01

    Thank you to everyone for helping!

    Final solution: RewriteRule ^/?i(/.*)?/company /company [L,NC]

Leave a reply to - About URL that doesn't really exist

◀ Go back