这是一个相对标准的问题,但我似乎无法让它在已经进行重写的 URL 上工作。
例如,我有这个网址:
http://example.com/this-is-rewritten/
https://example.com/this-is-rewritten/
应该去:
http://www.example.com/this-is-rewritten/
https://www.example.com/this-is-rewritten/
我想确保它总是在前面是 WWW,如果它不是子域 URL。所以,如果我们有:
http://subdomain.example.com/this-is-rewritten/
那不应该去万维网。这是我到目前为止所拥有的,但它会将您发送到带有查询字符串的底层 URL,而不是相同的“/this-is-rewritten/” URL。此外,应该保留 http 或 https。
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?:www.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://%2%3 [R=301,L]