php - Wordpress 类型 htaccess 如果是 url 有条件使用此规则?
问题描述
我有这个代码;
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]
# Send all remaining (routable paths) through index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Determine and use the actual base
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
RewriteRule ^.*$ %2indexsef.php [QSA,L]
我想在脚本之外使用替代 sef 端,但我不知道起始行..
如果网址有“/announcements/ ”或“/contact/ ”或“/contact”或blabla使用;
RewriteRule ^.*$ %2other.php [QSA,L]
我怎样才能做到这一点?
解决方案
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]
#insert new rules here
RewriteCond %{REQUEST_URI} "(^/announcements|/contact)" [NC]
RewriteRule gotothisfile.php
# Send all remaining (routable paths) through index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Determine and use the actual base
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
RewriteRule ^.*$ %2indexsef.php [QSA,L]
RewriteCond 的一个常用规则是检查它是否以某些东西开头。您可以通过将 ^ 放在开头来做到这一点。在您的示例中, /contact/ 和 /contact 都以相同的字母开头,因此您无需单独处理它们。
管道字符 | 用于允许匹配不同的单词。
确保不要将 $ 放在规则的末尾,因为这意味着“url 结束”
推荐阅读
- c++ - 如何在鼠标钩子进程中发送鼠标输入时避免延迟?
- python-3.x - 在类中导入模块,但在类方法中使用模块时出现名称错误
- javascript - 如何以角度显示拖放图像的预览?
- azure-devops - 密码推送部署密钥是否被视为敏感?
- c# - 如果单元格有错误,如何使用 C# 获取 excel 的值
- java - 如何将公共变量从 Multiboxtracker 扩展到另一个类?(Tensorflow Lite)
- c# - 如何使用 c# 在框架 v4 中检测 bot 的空闲状态?
- file - 如何使用 JS 打开文件选择器?
- android - 二维产品口味,Android工作室?
- javascript - 在 Parse 平台的查询中选择嵌套字段