jonniejoejonson Posted May 20, 2011 Share Posted May 20, 2011 I have the following in an htaccess file to prefix a www. incase a user has left it blank... RewriteCond %{HTTP_HOST} ^mysite\.org$ [NC] RewriteRule ^(.*)$ http://www.mysite.org/$1 [L,R=301] Is there another way of doing this, or a way to include the possibilty of needing to rewrite to https:// Kind regards J Quote Link to comment Share on other sites More sharing options...
requinix Posted May 20, 2011 Share Posted May 20, 2011 That's pretty much how it's done - nothing wrong with it. Not much room to do it differently. FWIW, here's what I do: RewriteCond %{HTTP_HOST} !^www.example.com$ RewriteRule ^ //www.example.com%{REQUEST_URI} [L] The differences are: 1. Mine checks whether the hostname is not what I want, as opposed to whether it is what I don't want. 2. I don't match the URL in the RewriteRule because it doesn't have to - %{REQUEST_URI} gives the same information. 3. It doesn't include the "http:" - redirecting to "//www.example.com" will keep the same protocol (http: vs https:) but change everything else. With that pattern, yours would look like RewriteCond %{HTTP_HOST} !^www.mysite.org$ RewriteRule ^ //www.mysite.org%{REQUEST_URI} [L] Quote Link to comment Share on other sites More sharing options...
jonniejoejonson Posted May 24, 2011 Author Share Posted May 24, 2011 requinix thats what im talking about.. thanks for that. regards J Quote Link to comment Share on other sites More sharing options...
jonniejoejonson Posted May 24, 2011 Author Share Posted May 24, 2011 requinix, i think i was a little hasty with my reply, becuase when i use your code, i get.. Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. IM guessing there is something ary... your continued support would be much appreciated.. kind regards J Quote Link to comment Share on other sites More sharing options...
requinix Posted May 25, 2011 Share Posted May 25, 2011 I'm wondering if the // is causing the problem. Never tried it before. Maybe adding a [R] would resolve any ambiguities. Anyway, what does Apache's error log say? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.