将域下的所有请求重定向到正在建设的文件夹

Mar*_*iaZ 3 .htaccess

我一直在尝试使用以下内容将域下的所有请求重定向到建设中的文件夹:

 RewriteEngine On
 RewriteCond %{REQUEST_URI} !=/underconstruction/
 RewriteRule ^ /underconstruction/ [R=301] 
Run Code Online (Sandbox Code Playgroud)

但它似乎不起作用。

我试过这个(它有效):

RewriteEngine On
RewriteCond %{REQUEST_URI} !=/underconstruction/underconstruction.html
RewriteRule ^ /underconstruction/underconstruction.html [R=301]
Run Code Online (Sandbox Code Playgroud)

但是我没有看到它附带的图像和 CSS。

有谁有想法吗?

Fel*_*a A 5

也许一种解决方案是从规则中排除所有图像和 CSS 文件,如下所示:

Options +FollowSymlinks -MultiViews
RewriteEngine On
# Add or remove file types in the next line if necessary.
RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif|bmp|js)  [NC]
RewriteCond %{REQUEST_URI} !underconstruction\.html  [NC]
RewriteRule .*   /underconstruction/underconstruction.html [R=302,L]
Run Code Online (Sandbox Code Playgroud)

其他选项是将这些文件的链接中的相对路径替换为绝对路径,或者使用本答案中所述的 BASE 元素