如何创建并非真正存在的网址?例如,https://twitter.com/i/notifications- 作品。当您从链接中删除/notifications时,您会收到https://twitter.com/i/- 不起作用。但这个URL /i/并不存在。关于并非真正存在的网址
我该怎么做?
如何创建并非真正存在的网址?例如,https://twitter.com/i/notifications- 作品。当您从链接中删除/notifications时,您会收到https://twitter.com/i/- 不起作用。但这个URL /i/并不存在。关于并非真正存在的网址
我该怎么做?
您可以创建一个.htaccess文件,通过一个PHP文件路由所有请求,然后使用该PHP文件中的逻辑来确定url是否存在。例如,你可以用我的笨.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";
}
你的'RewriteRule'传递请求的URL路径为_path information_(即'__SERVER ['PATH_INFO']'),而不是查询字符串。 – DocRoot
@DocRoot DOH!你是对的。正在编辑... –
您可以通过编辑.htaccess
文件来使用URL重写。如果.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。
喜欢的东西是什么? –
你是怎么做的..有没有问题,你面临..? –
这就是所谓的重写请求。您可以搜索该 – MiltoxBeyond