php - RewriteRule 适用于特定目录
问题描述
这是.htaccess中使用的代码,
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /blog/index.php?a=$1 [NC,L]
我想将它应用于特定目录,我无法应用此规则,但目前它会将未找到的整个网站的 url 重定向到domain/blog/index.php
解决方案
使用 RewriteCond。当您想将规则应用于特定条件时。
例如,
# Include in the next line all folders to include
RewriteCond %{REQUEST_URI} (folder1|folder2|folder3) [NC]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /blog/index.php?a=$1 [NC,L]
或通过添加一个相反的方式!
# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI} !(folder1|folder2|folder3) [NC]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /blog/index.php?a=$1 [NC,L]
另外,请记住,在某些情况下,Wordpress 会忽略 htaccess 文件
在某些情况下,将自定义内容添加到块中会阻止这种情况,但并非总是如此。这取决于正在使用的插件。
## BEGIN - My Custom Redirects
<IfModule mod_rewrite.c>
.....
</IfModule>
## END - My Custom Redirects
推荐阅读
- python - 经过时间后删除散点图中的一个点 - matplotlib
- shopify - 如何仅在特定页面上加载脚本标签?(购物)
- typescript - 导入webpack或htmlWebpackPlugin后构建webpack的几个错误
- google-cloud-platform - 写入 BigQuery 表的最低 IAM 权限?
- python - Django 中的 OpenTelemetry Python Auto Instrumentation 出现错误
- node.js - Node JS 不使用 SendGrid
- gitlab-api - gitlab api v4 未读取所有组标签
- flutter - 任务“:mecab_dart:externalNativeBuildDebug”执行失败
- python - 将多个数值列转换为值和类别列
- filter - ffmpeg可以检测视频的单色部分并相应地有条件地设置过滤器参数