php - 重定向 url 与 htaccess 完全匹配,如区分大小写
问题描述
如果查询字符串或 index.php 之后的任何内容,重定向 url 与 htaccess 完全匹配不重定向
Redirect This Page: https://example.com/demo/index.php
To Page: https://example.com/ (home page)
But Do Not redirect: https://example.com/demo/index.php/*
Do NOT redirect: https://example.com/demo/index.php/password
Do NOT redirect https://example.com/demo/index.php?m=page
not redirect if any other combination
only redirect https://example.com/demo/index.php to https://example.com/
这个脚本不工作
RewriteEngine On
RewriteBase /
RewriteRule ^demo/index.php /demo/index.php?m=page[L,NC,END]
RewriteRule ^demo/index.php$ https://example.com/ [L,R=301]
解决方案
只重定向
https://example.com/demo/index.php
到https://example.com/
如果您只想重定向那个确切的URL,而不需要查询字符串,那么您需要反转现有规则并包含一个额外的条件来检查 QUERY_STRING 是否为空。RewriteRule
唯一与 URL 路径匹配的,不包括查询字符串。
您还在第一条规则中的 flags 参数之前缺少一个空格。
例如:
# Redirect exact URL to home page
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^demo/index\.php$ / [R=302,L]
# Redirect other URLs with query string OR path-info
RewriteRule ^demo/index\.php /demo/index.php?m=page [NC,L]
你不需要L
和 END
。
使用 302 进行测试,只有在确认它可以正常工作后才更改为 301。避免缓存问题。
推荐阅读
- ios - IOS Storyboard 序列化
- apache-nifi - 合并内容中的 Nifi CPU 峰值
- c# - 如何声明一个也可以在没有绑定的情况下设置的 DependencyProperty
- python - Python Flask 应用程序无法在 AWS Elastic Beanstalk 上部署 | 没有名为“应用程序”的模块
- python - 使用 matplotlib 中的数据值缩放标记大小和颜色
- bcp - BCP 实用程序最大错误被忽略
- javascript - 处理错误时如何在 ember-data 中设置自定义响应 json
- dspace - DSpace XMLUI Batch-Importer:导入失败(没有这样的文件或目录)/错误:权限被拒绝
- apache-spark - 如何在 pyspark 中创建新列,其中条件取决于列的后续值?
- android-studio - 在 Android Studio 中,如何更改 Flutter 命名约定?