大网数据广告活动
网站运营与故障问答

How can I get a regular expression to only match an empty string? (In a .htaccess file)

· 52CE 我爱测

I try to make a regular expression in a .htaccess file, that matches only an empty string. I have tried many things, but it seems like it’s impossible. For example, I tried ^$ , but it's looking for "" that will always exist in a…

问题原文

原帖链接 · MadsHaupt · CC BY-SA 3.0

I try to make a regular expression in a .htaccess file, that matches only an empty string.

I have tried many things, but it seems like it’s impossible. For example, I tried ^$, but it's looking for "" that will always exist in a string.

So I seek answers to it all possible.

If possible, I would like to hear how to extend such a regular expression together.

Here is the content of my .htaccess file:

RewriteEngine On
RewriteRule ^$ https://stald-mariendal.dk/index_tekst [R=302,L]
RewriteRule ^guestbook.html$ https://stald-mariendal.dk/gaestebog [R=301,L,NE]
RewriteRule ^sites/guestbook.html$ https://stald-mariendal.dk/gaestebog [R=301,L,NE]
RewriteRule ^guestbook$ https://stald-mariendal.dk/gaestebog [R=301,L,NE]
RewriteRule ^(\w+).html$ https://stald-mariendal.dk/$1 [R=301,L,NE]
RewriteRule ^sites/(\w+).html$ https://stald-mariendal.dk/$1 [R=301,L,NE]
RewriteCond %{HTTPS} on
RewriteRule ^(\w+)$ ?site=$1.html [L]
RewriteCond %{HTTPS}| off
RewriteRule (.*) https://stald-mariendal.dk%{REQUEST_URI} [R=301,L,NE]

社区高分解答

原帖链接 · Rounin · CC BY-SA 3.0

I wasn't convinced this would work, but I've tested it and it does seem to.

Quite simply:

^.{0}$

Where:

^ is the start of the match

. is any character (except newline)

{0} is precisely zero times

$ is the end of the match

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2015-04-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。