.htaccess 带或不带斜杠的屏蔽目录
.htaccess masking directory with or without slash
我试图用一些静态 html 内容来屏蔽一个目录,简单的例子是这样的:
RewriteRule ^something/?$ sub_directory/something/
现在,当用户关注像
这样的 ulr 时
www.example.com/something/
一切正常,静态页面从 sub_directory/something
加载 css 和图像。但是当用户遵循这样的 url 时:www.example.com/something
(没有尾部斜杠),应用程序 returns 404 错误。
我在这里做错了什么?
我试过了:
RewriteRule ^something(.*) sub_directory/something/
但是这样,只有html内容被加载,没有任何js、css或图像文件。
你的规则是这样的:
RewriteEngine On
RewriteRule ^(?:js|css|images)/.+$ sub_directory/something/[=10=] [L,NC]
RewriteRule ^something(?:/.*)?$ sub_directory/[=10=] [L,NC]
并将此添加到您页面 HTML 的 <head>
部分下方:
<base href="/sub_directory/something/" />
这样每个 亲戚 URL 都是从那个基础 URL 解析的,而不是从当前页面的 URL.
我试图用一些静态 html 内容来屏蔽一个目录,简单的例子是这样的:
RewriteRule ^something/?$ sub_directory/something/
现在,当用户关注像
这样的 ulr 时www.example.com/something/
一切正常,静态页面从 sub_directory/something
加载 css 和图像。但是当用户遵循这样的 url 时:www.example.com/something
(没有尾部斜杠),应用程序 returns 404 错误。
我在这里做错了什么?
我试过了:
RewriteRule ^something(.*) sub_directory/something/
但是这样,只有html内容被加载,没有任何js、css或图像文件。
你的规则是这样的:
RewriteEngine On
RewriteRule ^(?:js|css|images)/.+$ sub_directory/something/[=10=] [L,NC]
RewriteRule ^something(?:/.*)?$ sub_directory/[=10=] [L,NC]
并将此添加到您页面 HTML 的 <head>
部分下方:
<base href="/sub_directory/something/" />
这样每个 亲戚 URL 都是从那个基础 URL 解析的,而不是从当前页面的 URL.