Simple apache redirect - apache

How can I redirect all images from www.example.com and example.com to images.example.com?
Here is some code I found online but I don't understand much and it doesn't work as expected
edit
#step 1 redirect ALL images from any domain to images.example.com
RewriteCond %{REQUEST_URI} ^/(.+)\.(gif|png|jpg|jpeg|jfif|bmp|css|js)$ [NC]
RewriteRule ^(.*)$ http://images.example.com/$1 [L,R=301]
#step 2 redirect non www to www
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#step 3 redirect ALL non images from images.example.com to www.example.com
RewriteCond %{REQUEST_FILENAME} !\.(gif|png|jpg|jpeg|jfif|bmp|css|js)$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Any help would be really appreciated!
Thanks!

Do this if you want to redirect all images to the subdomain.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(.+)\.(gif|png|jpg|jpeg|jfif|bmp|css|js)$ [NC]
RewriteRule ^(.*)$ http://images.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^images\.example\.com [NC]
RewriteCond %{REQUEST_URI} !^/(.+)\.(gif|png|jpg|jpeg|jfif|bmp|css|js)$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Related

Redirect all website link www to non www and http to https using .htaccess

When I go to https://www.example.com/webinars.php.
I want to be redirected to https://example.com/webinars.php
But Its not working.
My current .htaccess file is:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
Is this what you want?
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.([^\.]+\.[^\.]+)$
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

htaccess redirect 1 domain to http, others to https. all for non-www

I use htaccess to load Magento websites.
the problem is that I have 1 domain without SSL, is it possible to redirect just this 1 domain to http, while any others will be redirected to https. All domains should point to non-www version.
My current htaacces:
Options +SymLinksIfOwnerMatch
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} .*abc\.com [NC]
RewriteRule .* - [E=MAGE_RUN_CODE:abc]
RewriteCond %{HTTP_HOST} .*abc\.com [NC]
RewriteRule .* - [E=MAGE_RUN_TYPE:website]
RewriteCond %{HTTP_HOST} .*qwe\.de [NC]
RewriteRule .* - [E=MAGE_RUN_CODE:qwe]
RewriteCond %{HTTP_HOST} .*qwe\.pl [NC]
RewriteRule .* - [E=MAGE_RUN_TYPE:website]
RewriteCond %{HTTP_HOST} .*zxc\.fr [NC]
RewriteRule .* - [E=MAGE_RUN_CODE:zxc]
RewriteCond %{HTTP_HOST} .*zxc\.fr [NC]
RewriteRule .* - [E=MAGE_RUN_TYPE:website]
I like qwe.de to be redirected to http. while any other domain should point to https.
This is a problem with the htaccess not with magento
Try with this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^metrikstudios\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}

Redirect only images to static domain

How it's possible to 301 redirect all image (png, jpg, gif) requests from www.example.com to static.example.com?
My htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Any idea?
This should do it for you.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{REQUEST_URI} ^/(.+)\.(gif|png|jpg)$ [NC]
RewriteRule ^(.*)$ http://static.example.com/$1 [L,R=301]
Let me know how it works for you.

Redirect https and http www to https non www

I want to rewrite the following
http://example.com
http://www.example.com
https://www.example.com
to
https://example.com
tried using
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
It doesn't seems to be working
I'd say the easiest thing to do is just write two rules:
# First make sure HTTPS is being used
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Then make sure www isn't being used
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
You can use:
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]

force non www to www in htaccess

I have:
# BEGIN WithoutWWW
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
# END WithoutWWW
But it won't work. I can still access both www and non www versions. What am I doing wrong?
Try:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mysite\.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
//OR
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mysite\.com [NC]
RewriteRule ^(.*)$ [R=301,L]