Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/247824-allow-subdomain-but-not-www/
Share on other sites

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]

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.

  • 4 weeks later...

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.