.htaccess rewritecond rewrite案例级别2文件夹=信息

.htaccess rewritecond rewrite案例级别2文件夹=信息,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我想将.htaccess设置为重写: example.com/bla/info/ 到 到 我希望浏览器仍能显示: example.com/bla/info/txt/ 我不想在2级重写中重写,比如: example.com/bla/xxx/ 或 但是 也会起作用 example.com/strange/info/mytxt/ 这有意义吗 有什么帮助吗?如果模式以“^”开头,以“$”结尾,则仅当整个字符串匹配时,该规则才适用 RewriteRule ^/bla/info/$

我想将
.htaccess
设置为重写:

example.com/bla/info/

我希望浏览器仍能显示:

example.com/bla/info/txt/
我不想在2级重写中重写,比如:

example.com/bla/xxx/ 

但是

也会起作用

example.com/strange/info/mytxt/
这有意义吗


有什么帮助吗?

如果模式以“^”开头,以“$”结尾,则仅当整个字符串匹配时,该规则才适用

RewriteRule   ^/bla/info/$      /info/index.php?q=bla
RewriteRule   ^/bla/info/txt/$  /info/index.php?q=bla&t=txt
如果使用不使用[R]选项,浏览器中显示的URL将是用户输入的任何内容

你是想把它做成通用的吗?如果是这样,您可以使用正则表达式类型匹配和变量替换。要使“bla”与任何字符串匹配到下一个斜杠(/),请使用

在您的模式中,并在替换中引用$1

RewriteRule ^/([^/]+)/info/$          /info/index.php?q=$1
RewriteRule ^/([^/]+)/info/([^/]+)/$  /info/index.php?q=$1&t=$2
我建议您参考更多信息

[编辑。修正了规则,如原始海报所示,模式中不包括主机名。]

--

bmb

你让我走上了正确的道路

我的结局是这样的:

RewriteRule ^([^/\.]+)/info/?$ example/info/index.php?q=$1 [L]

非常感谢

哎呀,我忘了模式中没有显示主机名。我修正了答案。
example.com/strange/info/mytxt/
RewriteRule   ^/bla/info/$      /info/index.php?q=bla
RewriteRule   ^/bla/info/txt/$  /info/index.php?q=bla&t=txt
([^/]+)
RewriteRule ^/([^/]+)/info/$          /info/index.php?q=$1
RewriteRule ^/([^/]+)/info/([^/]+)/$  /info/index.php?q=$1&t=$2
RewriteRule ^([^/\.]+)/info/?$ example/info/index.php?q=$1 [L]