Php 如何写入htaccess通配符条件

Php 如何写入htaccess通配符条件,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我有这个 #RewriteCond %{HTTP_HOST} ^([^\.]+)\.localhost$ [NC] #RewriteRule ^$ /s/index.php?s=%1 [L] 在本例中,每当我为例如调用test.localhost时,它都会从localhost/s/index.php?s=test获取内容 但是,当我在地址栏中键入www.localhost时,它应该不会从/s/index.php获取内容 如何在htaccess中写入条件 例如,如果是www=notgetcont

我有这个

#RewriteCond %{HTTP_HOST} ^([^\.]+)\.localhost$ [NC]
#RewriteRule ^$ /s/index.php?s=%1 [L]
在本例中,每当我为例如调用test.localhost时,它都会从localhost/s/index.php?s=test获取内容

但是,当我在地址栏中键入www.localhost时,它应该不会从/s/index.php获取内容

如何在htaccess中写入条件


例如,如果是www=notgetcontentfrom/s/index.php

您只需要另一个
RewriteCond
来排除
www.

# Matches all subdomains:
RewriteCond %{HTTP_HOST} ^([^\.]+)\.localhost$ [NC]
# But then excludes www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^$ /s/index.php?s=%1 [L]

您只需要另一个
RewriteCond
即可排除
www.

# Matches all subdomains:
RewriteCond %{HTTP_HOST} ^([^\.]+)\.localhost$ [NC]
# But then excludes www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^$ /s/index.php?s=%1 [L]
那么您希望.localhost访问localhost/s/index.php?s=除了www.localhost之外的所有内容?最简单、最具体的方法是:

RewriteCond %{HTTP_HOST} ^([^\.]+)\.localhost$ [NC]
RewriteCond %{HTTP_HOST} !=www.localhost [NC]
RewriteRule ^$ /s/index.php?s=%1 [L]
这使用了RewriteCond的“词汇相等”检查,这应该是最准确的,比正则表达式快一点。

所以您希望.localhost访问localhost/s/index.php?s=除www.localhost之外的所有内容?最简单、最具体的方法是:

RewriteCond %{HTTP_HOST} ^([^\.]+)\.localhost$ [NC]
RewriteCond %{HTTP_HOST} !=www.localhost [NC]
RewriteRule ^$ /s/index.php?s=%1 [L]
这使用了RewriteCond的“词汇相等”检查,它应该是最准确的,并且比正则表达式快一点点