0

我想知道是否有人可以帮助解决一个小的 .htaccess 问题。

例如,在 .htaccess 文件中是这样的:

Options -Indexes 
RewriteEngine On 
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

# Normal
RewriteRule ^about$ ./about.html [L,NC]
RewriteRule ^news$ ./news.html [L,NC]
RewriteRule ^other$ ./other.html [L,NC]

如果您想强制执行 HTTPS 并且在 domain.com/about 之后没有正斜杠,这非常有用

我的问题是:

如何强制执行 HTTPS 并在末尾添加正斜杠,如下所示;

https://www.domain.com/about/

或允许用户在末尾添加正斜杠,而不会将其重定向到 404 错误页面。

它们也只是服务器主文件夹中的 HTML 页面。

有一次,您必须创建文件夹“about”、“news”、“others”等,并在每个文件夹中放置一个 index.html 文件,其中包含所有图像、css 和 js 等,以获得正斜杠。

我希望这可以做到。

谢谢!

4

1 回答 1

0

您需要添加一个规则来强制使用斜线,然后更改现有的重写,以便它们与之匹配:

Options -Indexes -Multiviews
RewriteEngine On 
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

# enforce the trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+[^/])$ /$1/ [R,L] 

# Normal
RewriteRule ^about/$ ./about.html [L,NC]
RewriteRule ^news/$ ./news.html [L,NC]
RewriteRule ^other/$ ./other.html [L,NC]

另外,为了安全起见,请关闭多视图。

于 2015-04-29T18:49:20.387 回答