我试图像删除“删除/”从链接
preg_replace("https://mywebsite.com/remove/","https://mywebsite.com/")
您可以使用str_replace()
。
str_replace($search, $replace, $subject)
$search
是针$replace
是更换$subject
是我们要修改字符串所以你的情况这将是:
str_replace('remove/', '', 'https://mywebsite.com/remove/');
使用str_replace从您的字符串替换特定部分。
echo str_replace("remove/", "", "https://mywebsite.com/remove/");
使用str_replace()
,
print(str_replace("/remove/", "", $link));
虽然@共感官的回答绝对会工作 - 我想提出另一种解决方案。如果你的链接到https://mywebsite.com/remove/
已收录,你可能需要使用一个301 Redirect到您的主页和/或发出删除页面上的410 "Gone"响应。
如果你将有很多被移动/缺少的资源,您可能需要使用插件像Simple 301 Redirects。否则,你可以简单地添加像.htaccess
规则
Redirect 301 /remove https://mywebsite.com/
或通过PHP添加它,如果你更舒适的与
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . site_url() );
exit();