Loading... <strong>说明:</strong>今天用服务器搭建了个<code>Apache</code>环境的站点,上<code>SSL</code>后,发现自己用惯了<code>Nginx</code>环境还不是很熟悉<code>Apache</code>的<code>301</code>定向,就自己在网上找了下方法,发现只需要修改<code>.htaccess</code>文件即可,这里说一下。 关于<code>Nginx</code>环境<code>301</code>请看:<a href="http://www.502435.com/1616.html" target="_blank" rel="noopener noreferrer">Nginx环境强制http 301跳转https的方法</a>,<a href="http://www.502435.com/1638.html" target="_blank" rel="noopener noreferrer">Nginx环境开启ssl后强制https 301全部指向www的方法</a>。 <div data-unique="方法"></div> <h2>方法</h2> 直接修改对应网站根目录的<code>.htaccess</code>配置伪静态文件就可以,没有这个文件的可以自建一个试试。 <strong>1、根目录域名</strong> <pre><code class="hljs apache"><span class="hljs-attribute"><span class="hljs-nomarkup">RewriteEngine</span></span> <span class="hljs-literal">On</span> <span class="hljs-attribute"><span class="hljs-nomarkup">RewriteCond</span></span> <span class="hljs-variable">%{SERVER_PORT}</span> 80 <span class="hljs-attribute"><span class="hljs-nomarkup">RewriteRule</span></span> ^(.*)$ https://www.yourdomain.com/<span class="hljs-number">$1</span><span class="hljs-meta"> [R,L]</span> </code></pre> <strong>2、子目录</strong> <pre><code class="hljs apache"><span class="hljs-attribute"><span class="hljs-nomarkup">RewriteEngine</span></span> <span class="hljs-literal">On</span> <span class="hljs-attribute"><span class="hljs-nomarkup">RewriteCond</span></span> <span class="hljs-variable">%{SERVER_PORT}</span> 80 <span class="hljs-attribute"><span class="hljs-nomarkup">RewriteCond</span></span> <span class="hljs-variable">%{REQUEST_URI}</span> 子目录文件夹 <span class="hljs-attribute"><span class="hljs-nomarkup">RewriteRule</span></span> ^(.*)$ https://www.yourdomain.com/子目录文件夹<span class="hljs-meta"> [R,L]</span> </code></pre> 将需要修改的修改下,填入<code>.htaccess</code>文件就可以了。 最后修改:2022 年 08 月 02 日 © 允许规范转载 打赏 赞赏作者 赞 0 如果觉得我的文章对你有用,请随意赞赏