将非www/ssl/trailing斜线的重写与.htaccess中的大写小写组合 [英] Combining rewrites for non-www/ssl/trailing slash with upper->lowercase in .htaccess

查看:89
本文介绍了将非www/ssl/trailing斜线的重写与.htaccess中的大写小写组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我可以直接进行重写,以捕获非www的URL,非SSL的URL和缺少尾部斜杠的URL,从而使用以下方法重定向到SSL,www和尾部斜杠:

So I have a straightforward rewrite to catch non-www URLs, non-SSL urls and urls missing a trailing slash to redirect to SSL, www and trailing slash using:

<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
RewriteCond %{HTTP_HOST} ^(.*[^/])$ [NC]
RewriteRule (.*\/)$ https://www.tierpoint/$1 [R=301,L] 
RewriteRule (.*[^/])$ https://www.tierpoint/$1/ [R=301,L]
</IfModule>

我想添加重写以将大写请求驱动为小写(在查询字符串中保留所有内容)

I'd like to add a rewrite to drive uppercase requests to lowercase (sparing anything in a query string)

我知道我可以循环遍历RewriteRule [A-Z]-[E = HASCAPS:TRUE,S = 1]

I know I can loop througRewriteRule [A-Z] - [E=HASCAPS:TRUE,S=1]

RewriteRule ![A-Z] - [S=28]
RewriteRule ^([^A]*)A(.*)$ $1a$2
...RewriteRule ^([^Z]*)Z(.*)$ $1z$2
RewriteRule [A-Z] - [N]
RewriteCond %{ENV:HASCAPS} TRUE
RewriteRule ^/?(.*) /$1 [R=301,L]

但是我该如何结合呢?

推荐答案

在您的网站根目录.htaccess中保存此内容:

Have it like this in your site root .htaccess:

RewriteEngine On

# add www, https
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI}  [R=301,L,NE]

# add a trailing slash is query string is not present
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^.]+?[^/]$ %{REQUEST_URI}/ [L,R=301,NE]

# convert URI to lowercase
# This requires Apache 2.4
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond expr "tolower(%{REQUEST_URI}) =~ m#(.+)#"
RewriteRule [A-Z] %1 [L,NE,R=301]

这篇关于将非www/ssl/trailing斜线的重写与.htaccess中的大写小写组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆