laravel - 在具有多个 htaccess 的 laravel 中路由
问题描述
我想要特定路线的特定 htaccess 文件。
例如,我想允许所有 ips 访问我网站的主路由,但阻止访问特定 ips 以仅支付路由或特定路由。
请帮我解决这个问题。
解决方案
您可以使用三种解决方案:
这里:
namespace App\Http\Middleware;
use Closure;
use Symfony\Component\HttpFoundation\IpUtils;
class RedirectInvalidIPs
{
protected $ips = [
'65.202.143.122',
'148.185.163.203'
];
protected $ipRanges = [
'10.11.3.1',
];
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
foreach ($request->getClientIps() as $ip) {
if (! $this->isValidIp($ip) && ! $this->isValidIpRange($ip)) {
return redirect('/');
}
}
return $next($request);
}
protected function isValidIp($ip)
{
return in_array($ip, $this->ips);
}
protected function isValidIpRange($ip)
{
return IpUtils::checkIp($ip, $this->ipRanges);
}
}
这里:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} /thisdirectoryandallcontents
RewriteCond %{REMOTE_ADDR} !=111.111.111.111
RewriteRule ^.*$ /maintenance.php [R=302,L]
推荐阅读
- css - 使用flex时如何使表格滚动?
- highcharts - Highcharts 直方图将最后一列和倒数第二列合并在一起
- angular8 - 如何解决 Angular 9 中的 i18n 未定义问题
- node.js - 我可以使用自定义 npmrc 文件运行“npm ci”吗?
- javascript - java脚本中将数据类型从“string”转换为“int”的问题
- outlook-addin - 在未打开清单的情况下捕获 Outlook 事件?
- php - 有没有办法在 phpmyadmin 中解码字符串
- android - 无法使用“com.arthenica:mobile-ffmpeg-full:4.4”修剪视频
- php - 获取 joomla 页面加载时间
- javascript - Geojson 未显示在地图上