.htaccess Redirect non-www domains including subdirectoies to www and exclude subdomains

和自甴很熟 提交于 2020-01-11 13:11:04

问题


I know there's tons of docs on any one of these items, but I can't seem to find the .htaccess code to do all of them together.

Goal/requirements:

  1. No prefix domain.tld redirects to www.domain.tld
  2. Subdomain'd domain (ex. mail.domain.tld) still goes to mail.domain.tld, i.e. does not get redirected to www.domain.tld
  3. Domain.tld/subdirectory redirects to www.domain.tld/subdirectory.

NOTE: domains will vary, but subdirectory will always be the same, i.e. all domains have the subdirectory. For example, domain1.ca/sub -> www.domain1.ca/sub, www.domain2.com/sub -> www.domain2.com/sub, domain3.org/sub -> www.domain3.org/sub

So far I have:

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

... which satisfies (1) and (2). How do I bundle (3) in their? Thanks!

来源:https://stackoverflow.com/questions/31082504/htaccess-redirect-non-www-domains-including-subdirectoies-to-www-and-exclude-su

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!