标签云

微信群

扫码加入我们

WeChat QR Code

I'm having difficulty constructing a non-www to www permanent redirect. Here are the conditions I need to meet...1.) Multi-domain support (multiple website domains pointed at the same directory on a server with their own dedicated copy of a database). This means using %{HTTP_HOST} and NOT a static domain name.2.) ALL possible pathes (or at least standards compliant ones) need to redirect; this means directories, HTTP queries, etc.3.) I'm using shared hosting, so I have access to the .htaccess file only.Here is what I'm working with right now:RewriteEngine onRewriteCond %{HTTP_HOST} ^%{HTTP_HOST}RewriteRule (.*) http://www\.%{HTTP_HOST}/$1 [R=301,L]Details:I'm testing with the browser cache disabled just in case.I've removed other syntax during testing to see what replies work in their own right.


and what is not working with your snippet?

2019年04月19日32分51秒

I don't know HTTP/1.1 very well, but is a 301 code valid as a response for every request? I think at the very least, the RFC says that for any requests other than GET or HEAD, the client should prompt the user to be redirected. See here.

2019年04月20日32分51秒

example.com/blog does not redirect, example.com does however.

2019年04月19日32分51秒

dreamlax — It is the responsibility of the browser author to make sure the client prompts the user when the server gives a 301 redirect response.

2019年04月20日32分51秒

Quentin: I know that, but what I'm saying is if he configures his server to redirect all requests (including POST, PUT, DELETE, etc) then his site might not function as expected, especially if the user declines the redirect.

2019年04月20日32分51秒

Thanks though that did not work.

2019年04月20日32分51秒

You’re using it with the obligatory RewriteEngine on, right?

2019年04月19日32分51秒

Of course though always good to ask for a clarification!

2019年04月19日32分51秒

Tried Opera instead, worked but ONLY for the root, not sub-directories work regardless of browser/empty cache.

2019年04月19日32分51秒

My bad, was trying my blog that has it's own .htaccess file; will have to append PER sub-directory where there is a dedicated .htaccess file. Thanks!

2019年04月20日32分51秒

This one is good, but Gumbo's makes sure that the URI scheme is kept too (so you aren't redirecting from HTTPS to HTTP).

2019年04月20日32分51秒