subdomain with www solve with htaccess - .htaccess

I have a problem with my subdomains. Normally every uses this kind of format: subdomain.domain.com and if this is entered there is no problem. When a user inputs www.subdomain.domain.com, the site doesn't work. I asked our hosting-support and they said I had to fix it with the .htaccess but I can't seem to find anything.
I found this but that is just for the domain and not for a subdomain:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.prosoccerdata\.com$ [NC]
RewriteRule ^(.*)$ http://prosoccerdata.com/$1 [R=301,L]
Many thanks!

This would take care of both main as well as sub-domains.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Related

.htaccess : Redirect all sites on my joomla website to root/main domain except one

So I really don't know what I'm doing wrong here, but I'm not too familiar with .htaccess stuff. What I want to do is to redirect every sub-site on my webspace to the main/root domain, except for one specific page which would be " my-website.de/impressum-datenschutz ".
This is what I got
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^/impressum-datenschutz$
RewriteRule ^(.*)$ http://my-website.de/ [R=301,L]
While the first part, redirecting from www to non-www works just fine, when I insert the second part, i get an error in my webbrowser telling me " this website redirects the request in a way so that it can never be finished" (roughly translated from German) .
What am I doing wrong?
Really thankful for any kind of help
For non-www to www use this
RewriteCond %{HTTP_HOST} !^www.yourdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/ [L,R=301]
For redirect all subdomains to domain try this
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^yourdomain.com$ [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]

Multistore force www to on-www per store

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.

Redirect with htaccess unless search

I'm not sure if this is possible, but here's whats going on.
I currently have an .htaccess rule to redirect example.com to store.example.com
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://store.example.com/[L,R=301]
This works great, however my search queries no longer work. What I'd like to do is redirect example.com to store.example.com unless I'm searching.
A sample search would look like this:
http://example.com/?s=my+search+query+string
Thank you in advanced for your help
Have you tried:
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{QUERY_STRING} ^!(s=(.*))$
Rewriterule ^(.*)$ http://store.example.com/ [L,R=301]

Non WWW to WWW redirection using htaccess File

I am using Codeigniter-.
My domain currently does not redirect to www version.
For example if I type mydomain.com then it stays mydomain.com. I want to redirect it to www.mydomain.com.
If someone types mydomain.com/controller/method then it should be www.mydomain.com/controller/method.
Another problem: I already tried other solutions but the problem is when it redirects to www version, it automatically adds "index.php" in the URL. But when I type www in the domain name then it works fine, no "index.php" in the URL. This problem occurs only during the redirection.
Here is my .htaccess file (I've removed the redirection code)
RewriteCond $1 !^(index\.php|system|rpc_relay.html|canvas.html|robots\.txt)
RewriteCond $1 !^(sitemap\.xml|export)
RewriteRule ^(.*)$ /index.php/$1 [L]
Any help would be greatly appreciated.
To redirect from http:// to http://www. , and also remove the route file (index.php) in the url, put these lines on your htaccess :
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteCond $1 !^(index\.php|images|css|js|styles|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
the domain is :
domain.com
folder with direct access :
images|css|js|styles
hope this help
I've used the following before:
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteCond %{HTTP_HOST} (.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
</IfModule>
To redirect domain.com to www.domain.com, you could use the following rewrite rule. Please replace domain.com with your own domain name.
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
I don't know why there are such complex RewriteRules answers, even though Gobhi has provided a nice generic solution (= whatever the domain name is, it works).
Here's my solution.
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
RewriteRule (.*)/index\.php$ $1/ [QSA]
</IfModule>

Mod_rewrite: How do I omit subdomains from rules?

Complete Apache newbie here. I'm trying to get my main URL to redirect to the www. Here's the code I'm using:
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
The problem is, this has wrecked my subdomains. sub.domain.com goes to www.sub.domain.com, which doesn't work. So what do I write to fix that?
This might be enough:
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
If all you're trying to do is make domain.com go to www.domain.com, then just use a RewriteCond that only matches domain.com at the start.

Resources