Php htaccess特定查询重写

Php htaccess特定查询重写,php,html,apache,.htaccess,mod-rewrite,Php,Html,Apache,.htaccess,Mod Rewrite,因此,我现在有了htaccess,可以在/之后获取任何内容,并将其作为查询 真的是这样吗 查询用于生成页面的内容类型。(div包含基于查询的不同信息) 但是,查询只能有3种不同的类型。所以我有一个问题,如果用户要去哪里,那么DIV将是空的,看起来很尴尬 所以本质上我只希望这3个特定的查询被接受,其他的一切都需要重定向到404页面 RewriteRule ^([^\.]+)$ index.php?type=$1 [L] 这段代码应该可以做到这一点 #Only your three types R

因此,我现在有了htaccess,可以在/之后获取任何内容,并将其作为查询

真的是这样吗

查询用于生成页面的内容类型。(div包含基于查询的不同信息)

但是,查询只能有3种不同的类型。所以我有一个问题,如果用户要去哪里,那么DIV将是空的,看起来很尴尬

所以本质上我只希望这3个特定的查询被接受,其他的一切都需要重定向到404页面

RewriteRule ^([^\.]+)$ index.php?type=$1 [L]
这段代码应该可以做到这一点

#Only your three types
RewriteRule ^bacon$ http://www.website.com/index.php?type=bacon [nc]
RewriteRule ^type2$ http://www.website.com/index.php?type=type2 [nc]
RewriteRule ^type3$ http://www.website.com/index.php?type=type3 [nc]
#Pass files and folders
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
#Throw 404
RewriteRule ^([^\.]+)$ - [L,R=404]
但您也可以简单地使用PHP发送404:

header('HTTP/1.1 404 Not Found');
exit();

您可以使用如下规则:

RewriteEngine On

RewriteRule ^(bacon|cheese|ham)/?$ index.php?type=$1 [NC,L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . - [L,R=404]

我已经测试了htaccess代码。问题是URL改变了它的预期用途。因此,我输出的链接是,但现在它被重写,当我希望url保持不变,但PHP知道幕后发生了什么。对不起,我的错误,只是删除括号中的r=301。