关于实际上不存在的网址


如何

创建一个实际上不存在的URL?例如,https://twitter.com/i/notifications - 有效。当您从链接中删除 /notifications 时,您会得到 https://twitter.com/i/- 不起作用。 但是这个网址/i/ 实际上并不存在。

我怎么做这样的东西?

您可以通过编辑文件来使用 URL 重写.htaccess。如果.htaccess不存在,则可以在项目根目录上创建一个。

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

以上会将url.com/picture.php?id=51转换为picture.php/Some-text-goes-here/51

以同样的方式,您可以使用您的 strtagy。

感谢大家的帮助!

最终解决方案:RewriteRule ^/?i(/.*)?/company /company [L,NC]

您可以创建一个 .htaccess 文件,该文件通过单个 PHP 文件路由所有请求,然后使用该 PHP 文件中的逻辑来确定 url 是否存在。 例如,您可以使用我的CodeIgniter .htaccess文件:

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

这仍然允许您指定不会重新映射的图像、css、js 等,但任何不以这些字符串开头的 url 都将路由到 index.php。 在 index.php 中,可以检查查询字符串以确定如何处理 url 并确定它们是否存在。

// 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";
}

最新更新