.htaccess - 如果文件不存在,则重定向到文件并保留 url
问题描述
我在以下文件夹中有一个 index.php:
https://example.com/folder1/folder2/index.php
如果网址是
https://example.com/folder1/folder2/93j3h233j3
然后重定向到 index.php 但 URL 应该保持不变!
我的想法:我首先调用一个没有 .php 的 php 文件,然后尝试重定向......
RewriteRule ^folder1/folder2/([^\.]+)$ /folder1/folder2/index.php?&%{QUERY_STRING}
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^folder1/folder2/(.*)$ /folder1/folder2/index.php? [R=302]
这不起作用。并保留名字!但如何?任何想法?
谢谢
解决方案
你可以有你的规则是这样的:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(folder1/folder2)/.+$ $1/index.php [L,NC]
无需使用您的第一条规则。
推荐阅读
- reactjs - 使用计数器组件按钮增加或减少分数两次
- next.js - vercel 在本地构建中工作时找不到模块或类型声明
- docker - 错误:ENOENT:没有这样的文件或目录,stat '/app/data/ca.srl'
- lektor - 如何解决 werkzeug 版本冲突?
- php - 为什么我的表格显示填写所有字段,即使我填写了它们
- spring-boot - 如何使用给定 wsdl 文件的安全 Web 服务
- python - 无法在 Windows 上使用 Anaconda 在 Spyder 中保存文件
- swift - 使用块变量的 SwiftUI 通用导航链接
- r - 从 Fabens von Bertalanffy 增长曲线的 nls() 模型中获取预测值
- android - Messenger 应用程序如何更新移动应用程序的用户活动(活动、非活动、5 分钟前活动)?