【问题标题】:Forcing HTTPS to one directory - Removing WWW强制 HTTPS 到一个目录 - 删除 WWW
【发布时间】:2013-08-08 08:48:02
【问题描述】:

我有一个小问题,这就是我用来强制 https 到结帐目录的方法,这只是一个预防措施,但问题是一旦你回到主页,它会将 www 插入 URL。

这是一个问题,因为视线的其余部分不使用 www,任何人都可以建议如何添加它以删除/阻止 www

# force https for all URLs in /checkout
RewriteCond %{HTTPS} =off
RewriteRule ^x9 https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# force http for all other URLs that are not in /checkout
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/x9
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

编辑

如果你说不是上面那个部分。这个问题只是在添加上面的代码之后才开始的,我以前从来没有遇到过这个问题,下面的代码已经在我的网站上几个月了。

 #Take off index.html
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule . http://www.%{HTTP_HOST}%1 [R=301,NE,L]

【问题讨论】:

  • 此代码不会强制 www 进入 URL。您是否有其他一些 .htaccess 代码/框架强制执行此操作。
  • @anubhava 我已经编辑了上面的帖子。谢谢。
  • 好吧,显然这个新代码在所有以 /index.html 结尾的 URI 中强制使用 www。是否现在要删除所有 URL 的 www,包括 http 和 https?
  • @anubhava 这不是以前,这就是为什么我有点困惑,但是是的,我想从所有 URL 中删除 www

标签: .htaccess http https


【解决方案1】:

在这种情况下,请像这样保留您的 .htaccess:

#Take off index.html
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%1 [R=301,L]

# force https for all URLs in /checkout
RewriteCond %{HTTPS} =off
RewriteRule ^x9 https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# force http for all other URLs that are not in /checkout
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/x9
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-12
    • 1970-01-01
    • 2011-05-10
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 2021-06-05
    • 1970-01-01
    相关资源
    最近更新 更多