自定义 .htaccess 重写规则
我想将所有内容重定向到一个脚本,例如 index.php?url=inputurl
使用 if/else 我想解析
index.php 中的 url,在我的自定义表中运行查询 url
- if url is mach: echo "ok"
- else 不执行任何操作
我应该如何在 WordPress 的根文件夹中设置 .htaccess?
示例:
custom_table 中的 URL:
- asd
- dfg
- ghj
如果用户放置:
www.mysite.com/asd
-> mod_rewrite 应该输出: www.mysite.com/index.php?url=asd
Else 如果用户输入:
www.mysite.com/zzz
->什么也不做
I want to redirect all to one script e.g. index.php?url=inputurl
With if/else I want to parse url
in index.php run query for url in my custom table
- if url is mach: echo "ok"
- else do nothing
How should I set .htaccess in root folder of Wordpress?
Example:
URLs in custom_table:
- asd
- dfg
- ghj
If user puts:
www.mysite.com/asd
-> mod_rewrite should output this: www.mysite.com/index.php?url=asd
Else if user puts:
www.mysite.com/zzz
-> do nothing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为以下 .htaccess 应该可以解决问题:
编辑: 在重写中不包含文件夹和文件(如 /js、/css 等),请在
之前添加以下行RewriteRule
行(参见注释):在 PHP 脚本中:
I think the following .htaccess should solve the problem:
Edit: to not include your folders and files (like /js, /css, etc.) in rewrite, add the following lines before the
RewriteRule
line (see comments):And in the PHP script:
您希望能够从数据库中读取数据,并且如果不匹配则不执行任何操作。
这将需要您运行代码来访问数据库,然后返回到 apache 进行处理,并且从 .htacccess 是不可能的(尽管它是来自 httpd.conf)。
.htaccess 解决方案是指定内联的所有“表”条目,如下所示。
You want to both be able to read from a database and do nothing if there is not match.
This would require you run code to access db then return back to apache to process and is not possible from .htacccess (though it is from httpd.conf).
The .htaccess solution would be to specify all the "table" entries inline as below.