Multistore force www to on-www per store - .htaccess

For a multistore PrestaShop I have, let's say: example.com [main domain] and example.org [extra store].
It's all setup nicely, without www, but when I visit www.example.org, it brings me to example.com.
I would say this helps:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.org [NC]
RewriteRule ^(.*)$ http://example.org/$1 [L,R=301,NC]
Or just for all the domains, I tried this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
But that also doesn't work. I put all of this before the # ~~start~~ Do not remove this-line.
Does anyone have a suggestion on how to approach this? Thanks in advance!

Try adding the following code to the .htaccess file in root directory of PrestaShop installation:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

I found the solution from the PrestaShop forum. I can't put links here. I will explain both www to non-www en non-www to www:
1. www to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} www.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
2. non-www to www
I haven't tried this because this is not setup in my PrestaShop installation. I've seen that people refer to this code many times, so it must work.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
I don't know why Knowband Plugin's code doesn't work. If someone could clarify that, it would be of great educational value.

Related

use htaccess to remove www from root and subdirectories

I am having an issue with my htaccess. I am trying to remove www. from my root and subdirectories. However, every example I have tried redirects to root.
IE www.example.com -> example.com But www.example.com/blog -> example.com
I need to remove www. from all directories and subdirectories, and keep the original path intended.
IE www.example.com -> example.com AND www.example.com/blog -> example.com/blog
I have used the following
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
and
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
and it is not working. Any help would be appreciated.
(Edit- after asked if I hade code above it)
I used this and it worked correctly
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]
I did not know drupal changed the way .htaccess worked. I apologize for not including that I was using this CMS in my original question
Have you tried this?
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Htaccess redirecting non-www to www

I have searched the web all over for a good generic .htaccess script for redirecting non-www to www, and currently i'm using this:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
This works fine, but if i go to a subdomain www. will be added. Does anyone has a good working redirect .htaccess script?
Try this :
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^([^\.]+)\.([^\.]+)\.([a-z]{2,4})$
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
#Vince What if the requested url is something like:
http://www.abc.example.com
IMHO, I think with your method it would never be redirected to:
http://www.example.com
How about this?
# Rewrite domain
RewriteCond %{HTTP_HOST} !^www\.([a-z1-9\-]+)\.([a-z]+)$ [NC] [and]
RewriteCond %{HTTP_HOST} ([a-z1-9\-]+)\.([a-z]+)$ [NC]
RewriteRule ^(.*)$ http://www.%1.%2/$1 [R=301,L]
Also, you guys may find these references useful:
https://www.drupal.org/node/93603
http://www.askapache.com/htaccess/modrewrite-tips-tricks.html

Remove wildcard subdomains but not existing ones with .htaccess

Hello!
I'm trying to set up my .htaccess file for wildcard subdomains, but I really have no clue how to do that.
I have "domain2" pointing to "domain1" as an alias, which is working perfectly, this is the code I'm using:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www)\.(.*)\.(.*)\.(.*) [NC]
RewriteRule ^(.*)$ http://%2.%3.%4/$1 [R=301,QSA,L]
RewriteCond %{HTTP_HOST} ^(.*\.?)domain2.co\.cc$ [NC]
RewriteRule (.*) http://%1domain1.co.cc/$1 [R=301,L]
I found the www redirect here btw: Optimize htaccess Wildcard Subdomain Code
Now, what I want is all non-existent subdomains to get removed and the ones that exist (like "blog.domain1.co.cc" to stay.
I hope someone can help me with this. Thanks!
RewriteEngine On
#no longer needed
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#don't redirect blog.example.com, forum.example.com and example.com
RewriteCond %{HTTP_HOST} ^((blog|forum)\.)?example\.com$
RewriteRule .* - [L]
#redirect the rest (including www.) to example.com
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
Try adding the following to your htaccess file.
#if these lines already exist, skip them
RewriteEngine On
RewriteBase /
#if its not www or discussions subdomain
RewriteCond %{HTTP_HOST} !^(www|discussions)\.domain1\.co\.cc$ [NC]
#redirect to www domain
RewriteRule .* http://www.domain1.co.cc%{REQUEST_URI} [R=301,L]
For the following question
redirects subdomains and subdirectories to the other domain, just like that: forum.old.com/thread/12038213 --> forum.new.com/thread/12038213
Try
RewriteEngine On
RewriteBase /
#if domain is old.com
RewriteCond %{HTTP_HOST} ^(.+)\.old\.com$ [NC]
#redirect to new.com
RewriteRule .* http://%1.new.com%{REQUEST_URI} [L,R=301]

htaccess mod rewrite ignoring forward slash

I've been searching and searching with no success for this simple htaccess redirect from a non-www URL to a www.
I have the following in the site's root htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
From what I've read this should work but instead of htp://domain.com/index.html going to htp://www.domain.com/index.html, it goes to htp://www.domain.comindex.html/ - Notice the ignored forward slash between .com and index.html
I have also tried the following rewrite conditions: (not all at once obviously)
RewriteCond %{HTTP_HOST} domain.com [NC]
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
Any help would be greatly appreciated.
NOTE: Domains would usually have 'http' but because of the stack overflow limit of urls, I've had to remove a 't' :)
Tested solution that just works (at least on all my production servers):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

Redirect the non-www URL to the www URL

I have referred all the related questions and tried the answer given, but it's not working for my site.
In my .htaccess file, I have written below code to redirect non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Are there any settings in Joomla that need to be set so it will use the .htaccess file?
This is what I use -
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
The differences are minor but should make it work. This works completely outside the scope of Joomla, you shouldn't have to do anything to Joomla for this to work.
You can put the following into your .htaccess to do this:
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
this works for me all the time

Resources