繁体   English   中英

.htaccess 将规则从动态 url 重写为静态 url(无查询字符串)

[英].htaccess rewrite rule from dynamic url to static url (no querystring)

我有一个带有表单的页面 - http://www.example.com/results/index.php 我需要这样做,以便可以从 url http://www.example.com/results/[anystring]访问表单。 也就是说,用户在浏览器地址栏中看到http://www.example.com/results/[anystring] url,但他们看到的是页面http://www.example.com/results/index的内容.php来自服务器。 “anystring”部分将被页面表单使用,如果它在预期字符串列表中,则表单将显示,“anystring”将是隐藏字段的值。 我知道如何执行此操作的 PHP 部分 - 如果它在预期字符串列表中,请使用表单中的“anystring”。 我不知道如何使用动态片段从 url 进行重写 - http://www.example.com/results/[anystring] - 访问静态页面 - http://www.example.com/结果/index.php

到目前为止,我有以下不起作用:

RewriteEngine On
RewriteBase   /results/
Rewrite Rule (\w+) index.php [L]

此外,还有其他 url 需要不受此影响,例如http://www.example.com/results/path/to/other/files.php

有人可以指出我正确的方向吗?

你相当接近。 您可以在results/.htaccess文件中使用此规则:

RewriteEngine On
RewriteBase /results/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM