cs.punk Posted September 25, 2011 Share Posted September 25, 2011 I have the following .htaccess file in root RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^example.co.uk$ [NC] RewriteRule ^(.*)$ http://example.co.uk/$1 [L,R=301] To allow my site being accessed from http:// and not http://www However I now have a subdomain and I can't seem to access it with this rule. I've tried to fiddle with it however my host seems to be taking ages for the .htaccess files to 'update'. Can anyone help me out? Quote Link to comment https://forums.phpfreaks.com/topic/247824-allow-subdomain-but-not-www/ Share on other sites More sharing options...
cags Posted September 25, 2011 Share Posted September 25, 2011 There should be no time delay with changes as the file is parsed on a per request basis. If your objective is to simply not allow www and use the root domain instead, why not just use... RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\.example\.co\.uk$ [NC] RewriteRule ^(.*)$ http://example.co.uk/$1 [L,R=301] Quote Link to comment https://forums.phpfreaks.com/topic/247824-allow-subdomain-but-not-www/#findComment-1272620 Share on other sites More sharing options...
cs.punk Posted September 25, 2011 Author Share Posted September 25, 2011 There should be no time delay with changes as the file is parsed on a per request basis. If your objective is to simply not allow www and use the root domain instead, why not just use... RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\.example\.co\.uk$ [NC] RewriteRule ^(.*)$ http://example.co.uk/$1 [L,R=301] Thanks for your help. Would this allow subdomains? Should I just keep this file in the root? As for the time delay I get the fact that it's on 'per request' however it seems to only take effect of a new .htaccess file after a few hours or so. Unless I'm doing something silly. This is a paid host too. Quote Link to comment https://forums.phpfreaks.com/topic/247824-allow-subdomain-but-not-www/#findComment-1272652 Share on other sites More sharing options...
cs.punk Posted September 28, 2011 Author Share Posted September 28, 2011 This doesn't seem to be working for a subdomain. I get a huge test.example.co.uk/test/test/test/test/test... url Bump? Quote Link to comment https://forums.phpfreaks.com/topic/247824-allow-subdomain-but-not-www/#findComment-1273546 Share on other sites More sharing options...
cags Posted September 28, 2011 Share Posted September 28, 2011 What other RewriteRules do you have? I don't see how that can cause a loop that would extend your URL, it clearly states if the subdomain is this, rewrite to that. There is no crossover. Quote Link to comment https://forums.phpfreaks.com/topic/247824-allow-subdomain-but-not-www/#findComment-1273643 Share on other sites More sharing options...
geudrik Posted October 27, 2011 Share Posted October 27, 2011 There's an easier way to do this... Change your DNS settings for the domain you purchased. www still just fail, where as the latter will work. As 'www' is technically a "sub-domain" anyway (semantics, psh), you can simply remove the A record for "www" at the DNS level, and it will no longer work. Quote Link to comment https://forums.phpfreaks.com/topic/247824-allow-subdomain-but-not-www/#findComment-1282666 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.