About URL that doesn't really exist

77 Views Asked by At

How can I create a URL that doesn't really exist? For example, https://twitter.com/i/notifications - works. When you remove the /notifications from the link you get https://twitter.com/i/ - Does not work. but this URL /i/ doesn't really exist.

How do I make something like that?

3

There are 3 best solutions below

2
On

Thank you to everyone for helping!

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

1
On

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";
}
0
On

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.