Hello Everyone,
I have just been reading up on seo and drupal and it was recommended to redirect non-www to www or vice-versa. Just don't keep both.
I am a little confused by the default .htaccess file as it seems to have some differing characters in the relevant lines in the file as compared to other examples I found on google.
Also, this particular site is a .co.uk so here's what I have in the file if I follow the drupal comments:
Lets' assume the website is called: www.joebloggs.co.uk
Here's the original section in the .htaccess file after the drupal install:
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
# RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
#
Here is my amended section in the .htaccess file:
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# adapt and uncomment the following:
RewriteCond %{HTTP_HOST} ^joebloggs\.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.joebloggs.co.uk/$1 [L,R=301]
#
What is confusing me is that in the first line there is a back slash between the joebloggs and the .co.uk
After doing some googling, none of the other examples I found had this back slash between the joebloggs and the .co.uk in the first line.
I am a complete beginner regarding .htaccess files and I want to make sure I have done the correct thing. I would kick myself I I got such an important thing wrong.
Please help.
If it is correct, a brief clarification what this back slash means, would be fantastic.
Thank you,
Sam
Comments
You should have the
You should have the following:
^joebloggs\.co\.uk$The backslash is an escape character in the regular expression. Without the slash, the dot will match any character, so I guess technically it will still work, but for the sake of being correct, put in the
\.which only matches a dot....http://en.wikipedia.org/wiki/Regular_expression
Hope that helps!
p.s. just so you know, the ^
p.s. just so you know, the
^matches the beginning, and the$matches the end of the string.Wow Mark - Many thanks.
Mark,
Thank you for your very swift and extremely clear reply!!!
My headache has gone :-)
Cheers,
Sam
No problem ;)
No problem ;)
basically, if a user types in
basically, if a user types in http://joebloggs.co.uk then he doesn't find the page while if you type joebloggs.co.uk he changes to the correct path..
I tried the following below but it doesn't work:
any suggestions on how to do this?
Authentically,
BassPlaya
redirect www.domain.tld/domain.tld but not other subdomains
hey
here's some .htaccess code
redirect domain.tld to www.domain.tld, but not other subdomains (like site2.domain.tld):
redirect www.domain.tld to domain.tld, but not other subdomains (like site2.domain.tld):
based on D7 .htaccess with inclusion of no other subdomains condition
Luís Pedro Algarvio
Site Reliability / DevOps Engineer.
Free and Open Source Software advocate.
Passionate about life and work.
lp.algarvio.org
THanks this worked!
THanks this worked!
Thank You
Thanks it's worked for me
I get this done using .htaccess
# adapt and uncomment the following:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Replace your domain with "example.com" above.
uncomment the already existing redirections in .htaccess file
Just use the below code. You can even redirect all users to HTTPS. Simply replace http with https. RewriteEngine On RewriteCond %{HTTP_HOST} ^abc.com$ RewriteRule (.*) http://www.abc.com/$1 [R=301,L]Check here for more conditions.