在本文中,我们将带你了解goDaddyWordPress.htaccess和SSL问题在这篇文章中,我们将为您详细介绍goDaddyWordPress.htaccess和SSL问题的方方面面,并解答w
在本文中,我们将带你了解goDaddy WordPress .htaccess 和 SSL 问题在这篇文章中,我们将为您详细介绍goDaddy WordPress .htaccess 和 SSL 问题的方方面面,并解答wordpress ssl后打不开常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的.htaccess – nivex上的韭菜,htaccess、Angular 和 PHP 服务器在同一个端口 proxy.config.json:.htaccess 与 RewriteEngine.htaccess 与重定向、Apache RewriteRule不适用于单个输入 解决方案1-修复.htaccess 解决方案2-制作一个.htaccess、apache 环境.htaccess 设置 301 跳转及常用.htaccess 技巧整理。
本文目录一览:- goDaddy WordPress .htaccess 和 SSL 问题(wordpress ssl后打不开)
- .htaccess – nivex上的韭菜,htaccess
- Angular 和 PHP 服务器在同一个端口 proxy.config.json:.htaccess 与 RewriteEngine.htaccess 与重定向
- Apache RewriteRule不适用于单个输入 解决方案1-修复.htaccess 解决方案2-制作一个.htaccess
- apache 环境.htaccess 设置 301 跳转及常用.htaccess 技巧整理
goDaddy WordPress .htaccess 和 SSL 问题(wordpress ssl后打不开)
如何解决goDaddy WordPress .htaccess 和 SSL 问题
goDaddy 网站存在 SSL 证书问题。我已经 3 年没有接触过这个网站了,我正在努力让它重新启动并运行。我昨天完成了添加 SSL 证书的步骤,该网站昨天运行良好,然后我在尝试加载该网站时收到 ERR_SSL_PROTOCOL_ERROR
。
我今天意识到我从未对 .htaccess
文件进行过编辑,因此我按照 this 教程中的步骤操作,并将以下块添加到我的 .htaccess
文件的顶部:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Header always set Content-Security-Policy "upgrade-insecure-requests;"
我的整个 htaccess 文件现在看起来像这样:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE]
Header always set Content-Security-Policy "upgrade-insecure-requests;"
RewriteCond %{HTTP_USER_AGENT} (google|yahoo|msn|aol|bing) [OR]
RewriteCond %{HTTP_REFERER} (google|yahoo|msn|aol|bing)
RewriteRule ^(.*)$ bev-anthropology.PHP?$1 [L]
# BEGIN wordpress
# The directives (lines) between "BEGIN wordpress" and "END wordpress" are
# dynamically generated,and should only be modified via wordpress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\\.PHP$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.PHP [L]
</IfModule>
# END wordpress
但我仍然在页面加载时收到 ERR_SSL_PROTOCOL_ERROR
。我还尝试了 this SO post 中的 ~8 个不同片段,仍然得到相同的结果。我完全迷失了:(感谢您的阅读。
.htaccess – nivex上的韭菜,htaccess
你好我试图在Nginx上设置韭菜,有人可以帮我转换htaccess吗?
Options +FollowSymLinks
IndexIgnore */*
DirectoryIndex index.PHP
<IfModule mod_rewrite.c>
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.PHP
RewriteRule . index.PHP?__chive_rewrite_on=1&%{QUERY_STRING}
RewriteRule ^$index.PHP?__chive_rewrite_on=1&%{QUERY_STRING}
</IfModule>
解决方法:
如果您在一个子目录“chive”中安装了chive,请执行以下操作:
location /chive/ {
try_files $uri chive/$uri/ /chive/index.PHP?q=$uri&$args;
}
没有子目录:
location / {
# ... existing options ... check twice!
try_files $uri $uri/ /index.PHP?q=$uri&$args;
}
而不是$args,你可以使用$query_string,根据http://wiki.nginx.org/HttpCoreModule(它读作:“与$args相同,除了这个变量是readonly.”)
Angular 和 PHP 服务器在同一个端口 proxy.config.json:.htaccess 与 RewriteEngine.htaccess 与重定向
如何解决Angular 和 PHP 服务器在同一个端口 proxy.config.json:.htaccess 与 RewriteEngine.htaccess 与重定向
我正在使用 Angular10 为前端制作一个 Web 服务,后端使用 PHP 和 MysqL。由于 Angular 与后端(或者至少是我见过的,我是 Angular 的新手)交互的方式是使用 http 请求,我们的 PHP 后端的工作方式与 API 非常相似。我们使用 XAMPP,因此 Apache 服务器侦听所有文件所在的同一路由,这样 Angular 就会向 localhost/myPHPfile.PHP 发出 http 请求,并在 json 中获取结果。
到目前为止一切顺利,但我们正在尝试实现登录和会话系统,但我们一无所知,因为我发现做了一些研究,当我们“进入”和“离开”时,PHP $_SESSION 会自行重置.PHP 文件。看起来我们需要做的是让 Angular 和 PHP 建立一个会话,让它们都监听同一个端口。问题是,如果您尝试让 PHP 服务器侦听端口 4200,它会抛出错误,因为该端口已经在使用中,所以我们不知道应该如何使用这两种技术来实现会话系统。
有什么想法吗?谢谢。
更新:我将写一些我在答案中分享的更多信息,以便更清楚。
Apache 服务器在端口 80 或 443 上运行,而 Angular 在端口 4200 上运行。我浏览网站的方式是使用 localhost:4200/view(与 Angular 分别路由),如果我需要来自数据库的任何数据,从 Angular 我向 localhost/myPHPfile.PHP 发出一个 http 请求,它管理与数据库的连接并获取数据,以 json 形式返回它,以便 Angular 可以通过 .suscribe() 获取它。
This is the php file path
我们制作的流程如下:
- 全局变量“userid”和“logged”分别为null和false
- 用户登录并输入有效数据
- Angular 向 login.PHP 发送一个 http 请求,以验证用户和密码是否正确。如果是这样,它会从 users 表中获取 id 并将 userid 设置为该数字,并将 logging 设置为 true。
- 完成此操作后,这些全局变量将设置为 $_SESSION(这是在 setSession.PHP 中完成的) -- 到目前为止,我们对 $_SESSION 进行了回显,结果是正确的
- 然后在 index* 中,我们向 getSession.PHP 发出一个 http 请求,它检查 $_SESSION 是否已设置或为空。如果已设置,则将全局变量设置为 $_SESSION 内的内容。到这里时,$_SESSION 是空的,没有以前的数据。
*只要用户使用按钮浏览网页,全局变量就会保持其值,但如果他浏览网址,这些变量将被清空,这就是为什么我们需要用 $_SESSION 再次设置它们
获得这些结果让我们搜索错误,我们发现 Apache 和 Angular 都需要监听同一个端口,因此这篇文章。
解决方法
我在我的环境中有相同类型的设置。请注意,有开发部分和生产部分。
我的 PHP 开发服务器运行在 80 端口,我的 angular ng-server 运行在 4200 端口
同居
关于在同一个端口上的部分...
开发
在开发时,我使用 ng serve
,但有一些额外的选项:
ng serve --host 0.0.0.0 --proxy-config proxy.config.json
proxy.config.json:
{
"/api/*":{
"target": "https://localhost","secure": false,"changeOrigin": true,"logLevel":"debug"
},"/auth/*":{
"target": "https://localhost","logLevel":"debug"
}
}
我的 php 项目中的所有内容都映射到 /api/*
或 /auth/*
或存在于该目录中。
在我的 php 项目的 .htaccess
文件中,我设置了错误处理程序或重定向以适合 angular 项目和我的 php.ini 文件。 选择其中一种方法:
.htaccess 与 RewriteEngine
RewriteEngine on
# angular rules
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
#php rules for nice urls
RewriteRule ^api/(.+)/ /api.php?service=$1 [NC,L]
RewriteRule ^auth/login/$ /login.php [NC,L]
.htaccess 与重定向
#redirect 400 and 404 errors to angular
ErrorDocument 400 index.html
ErrorDocument 404 index.html
生产
当我为 prod 打包我的 angular 应用程序时,我将它部署在与我的 php 应用程序相同的根目录中,并在相同的服务器和端口上提供所有服务。
会话处理
假设您有一个 login.php
映射到 /auth/login/
,它以 jwt 或 cookie 的形式创建令牌。
您需要编写在从 angular 到 php 的所有校准中包含该标记的逻辑。换句话说,您的每个 php 文件,例如api.php
需要在开始时验证它,并相应地采取行动。有几种方法可以做到这一点,我选择使用 jwts,并根据 JWT 中的范围让 angular 中的路由具有限制的保护。
Apache RewriteRule不适用于单个输入 解决方案1-修复.htaccess 解决方案2-制作一个.htaccess
当我在本地主机上玩它时,我发现它由于某种原因而开始循环。日志显示:
[core:error] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.,referer: http://subdomain.example.org/
[core:debug] AH00121: r->uri = /domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/favicon.ico,referer: http://subdomain.example.org/
[core:debug] AH00122: redirected from r->uri = /domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/domains/subdomain.example.org/favicon.ico,referer: http://subdomain.example.org/
...
[core:debug] AH00122: redirected from r->uri = /domains/subdomain.example.org/favicon.ico,referer: http://subdomain.example.org/
[core:debug] AH00122: redirected from r->uri = /favicon.ico,referer: http://subdomain.example.org/
即使我不知道为什么会循环,我还是找到了两种不同的解决方案。
解决方案1-修复.htaccess
我认为最正确的解决方法是the one @anubhava suggested。只需将最后一行更改为RewriteRule !^domains/ domains/%{HTTP_HOST}%{REQUEST_URI}
就足够了,我认为实际上更正确。
解决方案2-制作一个.htaccess
奇怪的是,另一种解决方案是将包含指令.htaccess
的{{1}}添加到RewriteEngine On
中。我认为这就是其他域起作用的原因。我不知道确切的原因,但是可以。
实际上,您可以使用以下否定条件规则来简化此操作:
RewriteRule !^domains/ domains/%{HTTP_HOST}%{REQUEST_URI} [L,NC]
apache 环境.htaccess 设置 301 跳转及常用.htaccess 技巧整理
apache 环境.htaccess 设置 301 跳转及常用.htaccess 技巧整理
无论是 Nginx,还是 Apache 都各自有优势,对于我们普通用户而言基本上也没有多大的区别。在虚拟主机环境中,基本上都是 Apache 环境。Apache 与 Nginx 两者区别之一就是伪静态的设置,前者则是在网站根目录设置.htaccess 文件,无论是伪静态,还是 301 跳转,甚至是防盗链和禁止某个 IP 的访问都可以很简单的设置。
Apache 环境.htaccess 设置 301 跳转及常用.htaccess 技巧整理
关于.htaccess 文件的设置和实际应用是相当广泛的,很多功能都可以利用这个小小的文件实现,只不过我们普通用户使用的并不多而已,比如我们使用最多的无非就是 WWW 或者非 WWW 301 跳转,顶多加上防盗链等功能,在这篇文章中就是.htaccess 文件的常见的用法。
第一、强制 www 域名 301 跳转
RewriteEngine on
RewriteCond %{HTTP_HOST} ^chinasoft\.com [NC]
RewriteRule ^(.*)$ https://www.chinasoft.com/$1 [L,R=301,NC]
我们将域名替换成自己的域名即可实现非 WWW 跳转到 WWW 域名。
第二、强制非 WWW 域名 301 跳转
RewriteEngine On
RewriteCond %{HTTP_HOST} !^chinasoft.com$ [NC]
RewriteRule ^(.*)$ http://chinasoft.com/$1 [L,R=301]
这里我们可以强制如果访问 www 域名前缀,会跳转到非 www 域名。
第三、强制 https 跳转地址
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.chinasoft.com/$1 [R,L]
同时满足强制跳转 https 和 www 的示例
# 强制跳转 https 和 www
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} ^chinasoft.io
RewriteRule ^(.*)$ https://www.chinasoft.io/$1 [R,L]
如何我们网站采用 SSL 证书,则一般需要强制跳转 https 路径,这里需要添加强制 80 端口的跳转。
第四、阻止无用的蜘蛛爬取
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (^$|FeedDemon|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|HttpClient|MJ12bot|heritrix|EasouSpider|Ezooms) [NC]
RewriteRule ^(.*)$ - [F]
第五、强制 / 斜杠结尾路径
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
第六、取消 / 斜杠结尾
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]
第七、将 A 页面 301 跳转到 B 页面
Redirect 301 /a.html https://www.chinasoft.com/b.html
第八、阻止某个 IP 访问
Order deny,allow
Allow from all
Deny from xxx.xxx.xxx.xxx
第九、禁止图片盗链
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(.+\.)?chinasoft.com [NC]
RewriteRule \.(jpg|jpeg|png|gif|bmp)$ - [NC,F,L]
第十、禁止被其他网页套用
SetEnvIf Request_URI "/starry-night" allow_framing=true
Header set X-Frame-Options SAMEORIGIN env=!allow_framing
第十一、全部重定向到 B 网站
RewriteEngine on
RewriteRule ^(.*)$ http://www.chinasoft.com/$1 [R=301,L]
如果我们更换域名或者希望域名流量全部导入新网站,这里可以全部跳转。
第十二、去掉默认首页 index.html
# 去掉 index.html
RewriteCond %{REQUEST_URI} ^(/index\.html)$ [NC]
RewriteRule ^(.*) / [R=301,L]
RewriteCond %{REQUEST_URI} !^(/index\.html)$ [NC]
RewriteCond %{REQUEST_URI} (/index\.html)$ [NC]
RewriteRule (.+)/index\.html /$1/ [R=301,L]
第十三、常用状态码全局跳转
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 405 /405.html
ErrorDocument 500 /500.html
ErrorDocument 503 /503.html
ErrorDocument 这里填 403,404 等错误信息调整页面,用来访问出现 404 页面等情况时的错误页面展示
总结,平时常用和不常用的.htaccess 伪静态、301、防盗链以及等设置功能。如果需要更多强大的 htaccess 功能则需要阅读官方文档。
Apache Rewrite 规则简介:
Rewirte 主要的功能就是实现 URL 的跳转,它的正则表达式是基于 Perl 语言。可基于服务器级的 (httpd.conf) 和目录级的 (.htaccess) 两种方式。如果要想用到 rewrite 模块,必须先安装或加载 rewrite 模块。方法有两种一种是编译 apache 的时候就直接安装 rewrite 模块,别一种是编译 apache 时以 DSO 模式安装 apache, 然后再利用源码和 apxs 来安装 rewrite 模块。
基于服务器级的 (httpd.conf) 有两种方法,一种是在 httpd.conf 的全局下直接利用 RewriteEngine on 来打开 rewrite 功能;另一种是在局部里利用 RewriteEngine on 来打开 rewrite 功能,下面将会举例说明,需要注意的是,必须在每个 virtualhost 里用 RewriteEngine on 来打开 rewrite 功能。否则 virtualhost 里没有 RewriteEngine on 它里面的规则也不会生效。
基于目录级的 (.htaccess), 要注意一点那就是必须打开此目录的 FollowSymLinks 属性且在.htaccess 里要声明 RewriteEngine on。
Apache mod_rewrite 规则重写的标志一览
1) R [=code](force redirect) 强制外部重定向
强制在替代字符串加上 http://thishost [:thisport]/ 前缀重定向到外部的 URL. 如果 code 不指定,将用缺省的 302 HTTP 状态码。
2) F (force URL to be forbidden) 禁用 URL, 返回 403HTTP 状态码。
3) G (force URL to be gone) 强制 URL 为 GONE,返回 410HTTP 状态码。
4) P (force proxy) 强制使用代理转发。
5) L (last rule) 表明当前规则是最后一条规则,停止分析以后规则的重写。
6) N (next round) 重新从第一条规则开始运行重写过程。
7) C (chained with next rule) 与下一条规则关联
如果规则匹配则正常处理,该标志无效,如果不匹配,那么下面所有关联的规则都跳过。
8) T=MIME-type (force MIME type) 强制 MIME 类型
9) NS (used only if no internal sub-request) 只用于不是内部子请求
10) NC (no case) 不区分大小写
11) QSA (query string append) 追加请求字符串
12) NE (no URI escaping of output) 不在输出转义特殊字符
例如:RewriteRule /foo/(.*) /bar?arg=P1%3d$1 [R,NE] 将能正确的将 /foo/zoo 转换成 /bar?arg=P1=zoo
13) PT (pass through to next handler) 传递给下一个处理
例如:
RewriteRule ^/abc (.*) /def$1 [PT] # 将会交给 /def 规则处理
Alias /def /ghi
14) S=num (skip next rule (s)) 跳过 num 条规则
15) E=VAR:VAL (set environment variable) 设置环境变量
301 跳转的实现是通过编辑网站主目录下的 301jump 文件来实现的。
本地保留一份与服务器上一样的文件(301jump),需要设置 301 跳转的时候可以通过编辑这个文件(添加需要的 301 跳转或者去除不需要的 301 跳转),然后通过 FTP 上传到网站目录下面 (test 的服务器上),覆盖掉以前的文件。
然后通过 test. 域名.com 的地址访问,测试 301 跳转是否生效。生效后同步到远程服务器即可。
301jump 文件的格式如下:
RewriteEngine on
RewriteRule ^a.html /b.html [R=301,L]
RewriteRule XXXXXXX XXXXXXX [R=301,L]
RewriteRule XXXXXXX XXXXXXX [R=301,L]
……………………………………..
下面介绍介绍跳转规则
第一行 RewriteEngine on 是开启跳转功能的配置
第二行开始
如:RewriteRule XXXXXXX XXXXXXX [R=301,L] 格式的是跳转
每一行表示一个跳转
我们的设置只要在文件末尾添加要设置的跳转,或者删掉要去除的跳转
跳转情况说明:(说明均是以 chinasoft.com 站点下的 301jump 编写为例)
情况一
http://www.chinasoft.com/a.html 跳转到 http://www.chinasoft.com/b.html
让站点下面的一个页面跳转到另一个页面
写法如下:
RewriteRule ^a.html /b.html [R=301,L]
情况二
http://www.chinasoft.com/a.html 跳转到 http://www.chinasoft.com/abc/b.html
让站点下面的一个页面跳转到非同级目录的另一个页面
写法如下:
RewriteRule ^a.html /abc/b.html [R=301,L]
http://www.chinasoft.com/abc/a.html 跳转到 http://www.chinasoft.com/b.html
让站点下面的一个页面跳转到非同级目录的另一个页面
写法如下:
RewriteRule ^abc/a.html /b.html [R=301,L]
情况三
http://www.chinasoft.com/word/index.html 跳转到 http://www.chinasoft.com/word/
让 chinasoft.com 站点下的 /word/index.html 文件夹的链接重新定向到 /word/ 目录,seo 优化
写法如下:
RewriteRule ^word/index.html /word/ [R=301,L]
情况四
http://www.chinasoft.com/word/ 跳转到 http://www.chinasoft.com/sentence/
让 chinasoft.com 站点下的 /word/ 文件夹的链接重新定向到 /sentence/ 下面,包含下层路径
例如:http://www.chinasoft.com/word/a.php
会被定向到 http://www.chinasoft.com/sentence/a.php
写法如下:
RewriteRule ^word/(.*)$ /sentence/$1 [R=301,L]
情况五
http://www.chinasoft.com/word/ 跳转到 http://www.chinasoft.com
让 chinasoft.com 站点下的 /word 文件夹的链接重新定向到 根目录 下面,包含下层路径
例如:http://www.chinasoft.com/word/a.php
会被定向到 http://www.chinasoft.com/a.php
写法如下:
RewriteRule ^word/(.*)$ /$1 [R=301,L]
情况六
http://www.chinasoft.com/a.html 跳转到 http://www.daniusoft.com/b.html
非相同域名站点的跳转
写法如下:
RewriteRule ^a.html http://www.daniusoft.com/b.html [R=301,L]
情况七
http://www.chinasoft.com 跳转到 http://www.daniusoft.com
让 chinasoft.com 站点链接重新定向到 www.daniusoft.com
写法如下:
RewriteRule (.*)$ http://www.daniusoft.com/$1 [R=301,L]
注意:这里 daniusoft.com 后面的 / 一定不能漏掉,如果漏掉的话,会出现如下错误:
chinasoft.com/a.html 跳转地址会是 daniusoft.coma.html (该地址不存在)
情况八
http://www.chinasoft.com 下的所有文件 跳转到 http://www.daniusoft.com 首页
让 chinasoft.com 站点所有页面重新定向到 www.daniusoft.com 首页
写法如下:
RewriteRule (.*)$ http://www.daniusoft.com [R=301,L]
情况九
动态页面取值跳转
support.iskysoft.com/index.php?submod=order&method=retrieve 页面
跳到指定页面
support.iskysoft.com/contact-support/retrieve-registration-code.html
写法如下:
^/index.php /aaa/%{QUERY_STRING}? [R=301,L]
^/aaa/submod=order&method=retrieve /contact-support/retrieve-registration-code.html [R=301,L]
小技巧:
如果需要让一条跳转不生效,暂时又不想删除此条跳转,可能以后还会用到。
在此条跳转前面加一个”#”,表示注释掉,此跳转不生效。
例如:
RewriteEngine on
#RewriteRule ^a.html /b.html [R=301,L]
RewriteRule XXXXXXX XXXXXXX [R=301,L]
RewriteRule XXXXXXX XXXXXXX [R=301,L]
站点中 a.html 到 b.html 的跳转将不会生效。
生效原则:先后顺序
跳转遵从从上往下优先匹配原则。
一旦前面有覆盖后面跳转的跳转存在,以前面跳转为准
例 1:
RewriteEngine on
RewriteRule ^a.html /b.html [R=301,L]
RewriteRule ^a.html /c.html [R=301,L]
RewriteRule ^a.html /d.html [R=301,L]
站点中 a.html 到 b.html 的跳转将会生效,其他两条不生效。
例 2:
RewriteEngine on
RewriteRule ^word/ (.*)$ /sentence/$1 [R=301,L]
RewriteRule ^word/a.html /a.html [R=301,L]
优先匹配 word/ 到 sentence / 的跳转。
由于历史原因,我们许多站点存在基于配置文件级的 301 跳转,这些跳转均优先于我们所编辑的 301jump 文件的跳转。
以下情况:
1、设置的跳转不生效。
2、跳转莫名奇妙的跳转到其他地址。
3、想取消一个跳转规则,怎么也找不到。
如果有大规模跳转需要设置(一次在 50 条以上), 把需要跳转的页面粘贴到新建文件 1,跳转到目标页面的粘贴到文件 2。
cat -n 1 >3
cat -n 2 >4
join -o 1.2,2.2 3 4 >5
完整站点示例:
root@server1 [/home/chinasoft0807/public_html]# more .htaccess
# 打开 zip 压缩
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/php
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^home\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /online/home.html [L]
</IfModule>
DirectoryIndex index.php index.html home.html
<Files 403.shtml>
order allow,deny
allow from all
</Files>
deny from 1.180.17.231
RewriteOptions inherit
<IfModule include_module>
Options +IncludesNoExec
</IfModule>
AddType text/html .shtml .html .htm
AddOutputFilter INCLUDES .shtml .html .htm
RewriteEngine on
# 强制跳转 https 和 www
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} ^chinasoft.io
RewriteRule ^(.*)$ https://www.chinasoft.io/$1 [R,L]
# 去掉 index.html
RewriteCond %{REQUEST_URI} ^(/index\.html)$ [NC]
RewriteRule ^(.*) / [R=301,L]
RewriteCond %{REQUEST_URI} !^(/index\.html)$ [NC]
RewriteCond %{REQUEST_URI} (/index\.html)$ [NC]
RewriteRule (.+)/index\.html /$1/ [R=301,L]
# /files 临时跳转 mm.edrasoft.com
Redirect 301 /files https://mm.chinasoft.com
# 404 调整默认首页
ErrorDocument 404 https://chinasoft.io/online/home.html
案例:
现象说明:
chinasoft.com下面有多语言站点 fr/jp/es/de 等
当访问 http://www.chinasoft.com/es/support.html 时,会自动跳转到主站的 http://www.chinasoft.com/support.html 页面
访问 https://www.chinasoft.com/es/support.html 没有问题,页面不会跳转
# 主站的rewrite规则配置
[/home/china007/public_html/es]# cat ../.htaccess
RewriteOptions inherit
RewriteEngine on
<IfModule include_module>
Options +IncludesNoExec
</IfModule>
AddType text/html .shtml .html .htm
AddOutputFilter INCLUDES .shtml .html .htm
order deny,allow
deny from env=BadReferrer
<Files 403.shtml>
order allow,deny
allow from all
</Files>
DirectoryIndex en/index.html index.html index.php
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/php
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType text/html "access plus 1 weeks"
ExpiresByType text/php "access plus 1 weeks"
ExpiresByType text/css "access plus 1 days"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType text/plain "access plus 1 weeks"
ExpiresByType image/jpeg "access plus 1 weeks"
ExpiresByType image/gif "access plus 1 weeks"
ExpiresByType image/png "access plus 1 weeks"
ExpiresByType application/pdf "access plus 1 month"
ExpiresDefault "access plus 1 weeks"
</IfModule>
RewriteCond %{HTTP_HOST} ^50\.97\.132\.226
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule (.*) https://www.chinasoft.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www.chinasoft.com [OR]
RewriteCond %{HTTP_HOST} ^chinasoft.com
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^(.*)$ https://www.chinasoft.com/$1 [R=301,L]
AddType application/edraw eddx
AddType application/x-newton-compatible-pkg pkg
AddType application/x-newton-compatible-dmg dmg
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^orderinfographics\.php$ "https\:\/\/www\.edrawsoft\.com\/orderinfographic\.php" [R=301,L]
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^download\/edrawmax\-cn\.exe$ "http\:\/\/www\.edrawsoft\.cn\/2download\/edrawmax\-cn\.exe" [R=301,L]
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^archives\/edrawmax\-cn\.dmg$ "http\:\/\/www\.edrawsoft\.cn\/2download\/edrawmax\-cn\.dmg" [R=301,L]
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^products\.html\&lang\=fr$ "https\:\/\/www\.edrawsoft\.com\/products\.html\?lang\=fr" [R=301,L]
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^products\.html\&lang\=jp$ "https\:\/\/www\.edrawsoft\.com\/products\.html\?lang\=jp" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^products\.html\&lang\=de$ "https\:\/\/www\.edrawsoft\.com\/products\.html\?lang\=de" [R=301,L]
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^shop2\/$ "http\:\/\/www\.edrawsoft\.cn\/shop\/" [R=301,L]
deny from 1.180.17.231
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^pages\/teamnotice\.html$ "https\:\/\/mm\.edrawsoft\.com\/pages\/teamnotice\.html" [R=301,L]
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^app\/index\.php$ "https\:\/\/www\.edrawsoft\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^en\/knowledge\/electricaldiagram\/$ "https\:\/\/www\.edrawsoft\.com\/en\/knowledge\/electrical\-diagram\/" [R=301,L]
RewriteRule ^en/(.*)$ https://www.chinasoft.com/$1 [R,L]
# 去掉index.html
RewriteCond %{REQUEST_URI} ^(/index\.html)$ [NC]
RewriteRule ^(.*) / [R=301,L]
RewriteCond %{REQUEST_URI} !^(/index\.html)$ [NC]
RewriteCond %{REQUEST_URI} (/index\.html)$ [NC]
RewriteRule (.+)/index\.html /$1/ [R=301,L]
# 多语言站点下的配置,添加针对 .htaccess文件并配置跳转规则
root@server1 [/home/china007/public_html/fr]# cat ../es/.htaccess
RewriteOptions inherit
RewriteEngine on
<IfModule include_module>
Options +IncludesNoExec
</IfModule>
AddType text/html .shtml .html .htm
AddOutputFilter INCLUDES .shtml .html .htm
# 将非https的站点强制跳转到https并且是多语言下
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} ^chinasoft.com
RewriteRule ^(.*)$ https://www.chinasoft.com/es/$1 [R,L]
# fr法语站的配置
root@server1 [/home/edra0604/public_html/fr]# more ../fr/.htaccess
RewriteOptions inherit
RewriteEngine on
<IfModule include_module>
Options +IncludesNoExec
</IfModule>
AddType text/html .shtml .html .htm
AddOutputFilter INCLUDES .shtml .html .htm
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} ^chinasoft.com
RewriteRule ^(.*)$ https://www.chinasoft.com/fr/$1 [R,L]
关于goDaddy WordPress .htaccess 和 SSL 问题和wordpress ssl后打不开的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于.htaccess – nivex上的韭菜,htaccess、Angular 和 PHP 服务器在同一个端口 proxy.config.json:.htaccess 与 RewriteEngine.htaccess 与重定向、Apache RewriteRule不适用于单个输入 解决方案1-修复.htaccess 解决方案2-制作一个.htaccess、apache 环境.htaccess 设置 301 跳转及常用.htaccess 技巧整理等相关知识的信息别忘了在本站进行查找喔。
本文标签: