小编pth*_*fan的帖子

用nginx重写对index.php的所有请求

在我的apache配置中,我有以下简单的重写规则

  1. 除非文件存在,否则将重写为index.php
  2. 在网址上你永远不会看到文件扩展名(.php)

我怎样才能在nginx中重写这个?

#
# Redirect all to index.php
#
RewriteEngine On

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} (/[^.]*|\.)$ [NC]
RewriteRule .* index.php [L]
Run Code Online (Sandbox Code Playgroud)

这是我的nginx服务器块现在的样子,但它不起作用:(

root /home/user/www;
index index.php;

# Make site accessible from http://localhost/
server_name some-domain.dev;


###############################################################
# exclude /favicon.ico from logs
location = /favicon.ico {
    log_not_found off;
    access_log off;
}   

##############################################################
# Disable logging for robots.txt
location = /robots.txt {
    allow all;
    log_not_found off; …
Run Code Online (Sandbox Code Playgroud)

nginx url-rewriting

53
推荐指数
6
解决办法
14万
查看次数

div之间的换行符会渲染一个空格.如何从HTML中消除它?

我有以下布局

<div style="width:100px">
    <div style="width:50%; display: inline-block;">
        div1
    </div>
    <div style="width:50%; display: inline-block;">
        div2
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

因为在html中,在结束和打开div(div1和div2)之间有一个变化线,浏览器添加一个"空格"字符代替换行符,这导致第二个div显示在第一个div下面.

但是,如果删除div1和div2之间的\n,则它们会相互显示,这是预期的行为.

<div style="width:100px">
    <div style="width:50%; display: inline-block;">
        div1
    </div><div style="width:50%; display: inline-block;">
        div2
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

然而,这使代码看起来很丑陋.我目前正在使用<DOCTYPE html>.我也试过切换到XHTML,但没有用.我很确定有一些方法可以消除这种换行符,任何想法?

仅供参考:我不想在渲染过程中使用浮点数或在PHP中解析我的html输出来删除换行符.

html tags line-breaks

13
推荐指数
2
解决办法
2万
查看次数

在剪切事件期间获取文本框的值

我在文本框中捕获了cut事件(jquery).我想要的是在切换事件触发期间获取文本框上的文本.

我尝试通过evt.originalEvent.clipboardData.getData('text')访问用户剪切的数据,但返回undefined.

我的目标是知道用户是否剪切了所有文本(文本框现在为空).

提前致谢

javascript jquery keyboard-shortcuts cut

7
推荐指数
2
解决办法
2098
查看次数

谷歌搜索结果页面中的搜索输入

如果你谷歌用于IMDB,你会注意到在附加链接(页面标题下的列表)之后你会得到一个搜索框.如果你在那里输入表单内容提交到imdb的搜索,imdb又返回imdb站点内的结果(见截图). 谷歌搜索页面上的网站搜索输入http://imageshack.us/a/img593/3320/googlesearchwidget.png

问题是,如何添加此功能?

此外,当您键入域并点击标签时某些浏览器(即chrome)上的某些网站会得到一个不错的搜索域名.tld:您输入的任何内容都会被发送到网站的搜索页面(再次参见第二个屏幕截图)

浏览器网站搜索技巧http://imageshack.us/a/img203/1696/chromesitesearch.png

第二个问题(不知怎的,我感觉这两者有关)我如何在我的网站上做到这一点?

xml seo html5 google-search

5
推荐指数
1
解决办法
1488
查看次数

Riverpod,在 BuildContext 和 Provider 之外读取状态

我正在努力弄清楚为什么这不起作用(而不是说明它应该起作用的文档)。

我有一个像这样的提供者

import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:putin_flutter_client/api/client.dart';
import 'package:putin_flutter_client/api/storage.dart';

final userProvider = StateNotifierProvider((_) => UserNotifier());

class UserNotifier extends StateNotifier<UserState> {
  UserNotifier() : super(UserState());

  set username(String username) {
    state = UserState(username: username, password: state.password, jwt: state.jwt);
    secureStorageWrite('username', username);
  }

  set password(String password) {
    state = UserState(username: state.username, password: password, jwt: state.jwt);
    secureStorageWrite('password', password);
  }

  set jwt(String jwt) {
    state = UserState(username: state.username, password: state.password, jwt: jwt);
    Client.jwt = jwt;
    secureStorageWrite('jwt', jwt);
  }

  String get jwt {
    return state.jwt;
  }

  Future<void> initState() async …
Run Code Online (Sandbox Code Playgroud)

dart flutter riverpod

5
推荐指数
2
解决办法
1266
查看次数

Macbook Pro 15",退格不能与 VIM 配合使用?

我刚拿到一台新的 15" macbook pro,似乎出于某种奇怪的(映射?)原因,在 vim 中我不能使用退格键(删除光标左侧的字符!)。但是,所有其他操作,包括删除(字符在光标右侧,即 fn+backspace)工作正常!

有人已经解决了这种奇怪的行为吗?

仅供参考,键盘具有德语布局,但在软件中我使用国际英语布局。在我的另一台笔记本电脑上(macbook pro 15" 但 2010 型号 - 虽然相同的软件但普通的英文国际物理键盘布局我从来没有遇到过这样的问题)

vim keyboard-shortcuts keymapping

2
推荐指数
1
解决办法
856
查看次数

@freezed copyWith 缺少密封类

在以下代码片段中,state.copyWith 函数不可用。

@freezed
class MyState with _$MyState {
  @JsonSerializable(fieldRename: FieldRename.snake, explicitToJson: true)
  const factory MyState({@Default(0) int counter,}) = _MyState;
  const factory MyState.initial({@Default(0) int counter}) = Initial;
  const factory MyState.loading() = Loading;
  const factory MyState.one() = One;
  const factory MyState.two() = Two;

  factory MyState.fromJson(Map<String, dynamic> json) =>
      _$MyStateFromJson(json);
}

class MyStateNotifier extends StateNotifier<MyState> {
  MyStateNotifier() : super(MyState.initial());

  Future<void> one() async {
    state = MyState.loading();
    await Future.delayed(Duration(seconds: 5));
    state.copyWith(counter: 1);
  }
}
Run Code Online (Sandbox Code Playgroud)

但是,当我删除密封类时,copyWith 函数可用。

@freezed
class MyState with _$MyState {
  @JsonSerializable(fieldRename: FieldRename.snake, …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-freezed

2
推荐指数
1
解决办法
5333
查看次数

PHP正则表达式 - 接受除1之外的所有正数

正则与我有爱与恨的关系.我需要匹配(接受)除了数字1和0之外的所有数字.将其视为数学而不是字符串,数字> = 2应匹配.另外请考虑这是Zend路由参数(reqs)的一部分所以我必须使用正则表达式,除非我想扩展Route类等等.:)

103 => 103
013 => 013
201 => 201
340 => 340
111 => 111
001 => no match
010 => 010
100 => 100
  1 => no match
000 => no match
 00 => no match
  0 => no match
Run Code Online (Sandbox Code Playgroud)

我尝试了一些变化[^1][|\d+](试图一次钉一个数字:D)但到目前为止,我已经失败了:(

搞定了!!

我正在寻找的正则表达式似乎如下

^([2-9]|[2-9]\d|[1-9]\d{1,})$
Run Code Online (Sandbox Code Playgroud)

php regex

1
推荐指数
1
解决办法
255
查看次数