我想将所有请求重定向到放置.htaccess的index.html
.htaccess的位置:
https://example.com/unknown/whatever/.htaccess
此请求:
https://example.com/unknown/whatever/article1
应重定向到
https://example.com/unknown/whatever/index.html
仅当我知道子文件夹路径时,它才对我有用:
RewriteEngine On
RewriteBase /
DirectorySlash Off
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /unknown/whatever/index.html [L]
有什么想法在子文件夹路径和计数未知的情况下如何使它工作?
答案 0 :(得分:1)
它对我有用(请求的URL-未知/不定/文章1)
RewriteEngine On
RewriteBase /
DirectorySlash Off
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)$ $1/index.html [L]
服务器文件结构:
unknown/whatever/article1/index.html
.htaccess
这也对我有用(要求的URL-未知/不定/任何文章1):
RewriteEngine On
RewriteBase /
DirectorySlash Off
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)/(.*)$ $1/index.html [L]
服务器文件结构:
unknown/whatever/index.html
.htaccess
请求:unknown/whatever/article1
.htaccess:
RewriteEngine On
DirectorySlash Off
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)$ index.html
文件结构:
unknown/whatever/index.html
unknown/whatever/.htaccess