Please help with the following question.
There is domain1.com, domain2.com, domain3.com. With the help of organized htaccess redirects to domain.com. But in the apache logs for domain.com, I do not see the referer, since when domain1 or domain2 request came.
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com?$ [NC]
RewriteRule ^$ http://domain.com/$1 [R=302,L]
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^rss\.domain1\.com$ [NC]
RewriteCond %{HTTP_HOST} !^contacts\.domain2\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=302,L]
RewriteCond %{HTTP_HOST} ^rss.domain1.com$
RewriteRule ^/?$ "http\:\/\/www\.google\.com" [R=302,L]
RewriteCond %{HTTP_HOST} ^contacts.domain2.com$
RewriteRule ^/?$ "https\:\/\/www\.google\.com" [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ / [R=302,L]
Related
I have multiple domains on one host, my .htaccess looks like this
RewriteEngine On
RewriteCond %{HTTP_HOST} web1.com$ [NC]
RewriteCond %{REQUEST_URI} !^/web_1/public/.*$
RewriteRule ^(.*)$ /web_1/public/$1 [L]
RewriteCond %{HTTP_HOST} web2.com$ [NC]
RewriteCond %{REQUEST_URI} !^/web_2/public/.*$
RewriteRule ^(.*)$ /web_2/public/$1 [L]
And it works so far. Now I want only web1.com, not web2.com, to redirect to https. How do I have to change the settings? (I am also thankful for tips about how to change my "implementation" so far, I am new to .htaccess and willing to learn more about it)
Try this :
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} web2.com$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
So , your rules will look like this :
RewriteEngine On
RewriteCond %{HTTP_HOST} web1.com$ [NC]
RewriteCond %{REQUEST_URI} !^/web_1/public/.*$
RewriteRule ^(.*)$ /web_1/public/$1 [L]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} web2.com$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTP_HOST} web2.com$ [NC]
RewriteCond %{REQUEST_URI} !^/web_2/public/.*$
RewriteRule ^(.*)$ /web_2/public/$1 [L]
I know its duplicate and there are a lot of answers in google, but nothing works for me, yet.
I'm not strong or even average with apache, but I'd like to exclude one url that starts from /test/ from HTTPS redirect.
//redirect not working
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^\/(/test/)
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
RewriteCond %{HTTP:X-Forwarded-Proto} https
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^\/(/test/)
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
//infinity loop
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{REQUEST_URI} ^\/(test)
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTP:X-Forwarded-SSL} =on
RewriteCond %{REQUEST_URI} !^\/test)
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]
//thats my first HTTPS redirect, tried to add RewriteCond to exclude test, but nothing works
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/test/ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
I'd appreciate for the help.
Found an answer by myself
# force https:// for all except some selected URLs
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/test/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force http:// for selected URLs
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /test/ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I have the following rules and conditions in my mod_rewrite and like to add HTTPS to it. I like to confirm the following it accurate before publishing it live.
Current Rules and Conditions
RewriteEngine On
RewriteCond %{REQUEST_URI} \.jpg$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /home/domain.com/public_html/missing.png [L]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^index.html$ http://www.domain.com/ [L,R=301]
New Rules and Conditions
RewriteEngine On
RewriteCond %{REQUEST_URI} \.jpg$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /home/domain.com/public_html/missing.png [L]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]
RewriteCond %{HTTPS} Off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^index.html$ https://www.domain.com/ [L,R=301]
RewriteEngine On
# always do domain/https redirs first
RewriteCond %{HTTPS} =off [OR]
RewriteCond %{HTTP_HOST} ^(?!www\.domain\.com$). [NC]
RewriteCond %{THE_REQUEST} ^\S+\s+/?(\S*)
RewriteRule ^ https://www.domain.com/%1 [NS,NE,L,R=301]
# remove index files from URLs, except from POST forms, etc. you can add more file extensions to the second condition
RewriteCond %{REQUEST_METHOD} ^(?:GET|HEAD)$
RewriteCond %{THE_REQUEST} ^\S+\s+/?((?:[^?/]*/)*?)index\.(?:html?|php|pl)(\?\S*)?(?:\s|$)
RewriteRule ^ https://www.domain.com/%1%2 [NS,NE,L,R=301]
# missing images
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(?:jpe?g|png|gif)$ /missing.png [NS,NC,L,DPI]
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.
All of a sudden this morning I'm having a problem with accessing the home page to my site.
I didn't make any changes so I'm not sure what the issue is. I'm guessing it has something to do with my .htaccess file.
All other pages to my site, I can access without a problem.
Below is my htaccess file. Any help would be appreciated. Thanks in advance.
Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^hats-n-caps/(.*)$ http://www.domain-domain.com/apparel/hats-n-caps/$1 [R=301,L]
RewriteRule ^electronics/laser-pointers/(.*)$ http://www.domain-domain.com/desktop-office/laser-pointers/$1 [R=301,L]
#RewriteCond %{HTTP_HOST} !^www.domain-domain.com$ [NC]
#RewriteRule ^(.*)$ http://www.domain-domain.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} (^(.*)/site-map)
RewriteRule ^site-map$ /inc/pages/site-map.php [L]
RewriteCond %{REQUEST_URI} (^(.*)/site-map/products-([0-9]+))
RewriteRule ^site-map/products-([0-9]+)$ /inc/pages/site-map.php?type=product&page=$1 [L]
RewriteCond %{REQUEST_URI} (^(.*)/site-map/catalogs-([0-9]+))
RewriteRule ^site-map/catalogs-([0-9]+)$ /inc/pages/site-map.php?type=catalog&page=$1 [L]
RewriteCond %{REQUEST_URI} (^(.*)/site-map/pages-([0-9]+))
RewriteRule ^site-map/pages-([0-9]+)$ /inc/pages/site-map.php?type=pages&page=$1 [L]
RewriteCond %{REQUEST_URI} (^(.*)-p-(.*).html*)
RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&%{QUERY_STRING}[L]
RewriteCond %{REQUEST_URI} (^(.*)-c-(.*).html*)
RewriteRule ^(.*)-c-(.*).html$ product_info.php?catalog_id=$2&%{QUERY_STRING}[L]
RewriteCond %{REQUEST_URI} !(^(.*)-c-(.*).html*|^(.*)-p-(.*).html*|^/index.php|^/sitemap.xml.*|^/info.php.*|^/google_base_feed.xml.*|^/BingSiteAuth.xml.*|^/test.html.*|^/test.*|^/ajaxplorer.*|/livechat.*|^/phpmyadmin.*|^/ControlPanel.*|^/actikare.*|^/amwater.*|^/phi.*|^/sas.*|^/blog.*|^/cfscg.*|^/chase.*|^/cleaver.*|^/clubz.*|^/medicone.*|^/net2ftp.*|^/college-net.*|^/ducks.*|^/fast-teks.*|^/gatesgroup.*|^/guesthouse.*|^/neighborcare.*|^/pdf.*|^/reedrill.*|^/survey.*|^/temp.*|^/templates.*|^/tidewater.*|^/tuthill.*|^/uploads.*|^/upload.*|^/_include.*|^/product_info.*|^/server_request.*|^/server_request_products.*|^/admin.*|^/img/.*|^/images/.*|^/spaw2?|^/static/.*|^/tmp/|^/_include/|^/robots.txt|^/LiveSearchSiteAuth.xml|^/favicon.ico|/SiteReturn/.*|^/inc/pages/site-map.php(.*)|^/carousel_products.php)
RewriteRule (.*)$ /index.php [L]
RewriteCond %{HTTP_HOST} ^domain-domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain-domain.com$
RewriteRule ^/?$ "\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^domaindomain\.co$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domaindomain\.co$
RewriteRule ^/?$ "\/" [R=301,L]
This line:
RewriteRule ^/?$ "\/" [R=301,L]
Is what's causing your redirect loop. Get rid of the entire rule:
# RewriteCond %{HTTP_HOST} ^domaindomain\.co$ [OR]
# RewriteCond %{HTTP_HOST} ^www\.domaindomain\.co$
# RewriteRule ^/?$ "\/" [R=301,L]
It essentially redirects requests to the root / to itself.