Situation: afwezigheden.eu is the main domain with a few coupled domains (= aliases?) like skatespots.be, inviteme.eu, halftwaalf.be... Now I'm trying to redirect those aliasses to a subfolder, without the users seeing it.
Al those sites are in a subfolder _DOMAINNAME. For example: skatespots.be is in afwezigheden.eu/_skatespots
Also I have an SSL certificate, so I would like to redirect all domains to https too.
I tried several things, the last one is this one, where skatespots seems to work and everything is redirected over https.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/_skatespots/
RewriteCond %{HTTP_HOST} ^(www\.)?skatespots\.
RewriteRule ^(.*)$ /_skatespots/$1 [L]
RewriteCond %{REQUEST_URI} !^/_halftwaalf/
RewriteCond %{HTTP_HOST} ^(www\.)?halftwaalf\.
RewriteRule ^(.*)$ /_halftwaalf/$1 [L]
RewriteCond %{REQUEST_URI} !^/_inviteme/
RewriteCond %{HTTP_HOST} ^(www\.)?inviteme\.
RewriteRule ^(.*)$ /_inviteme/$1 [L]
RewriteCond %{HTTP:X-Forwarded-Proto} !http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
What am i doing wrong?
What if you put the folder structure as this:
afwezigheden.eu/sites/skatespots.eu
afwezigheden.eu/sites/halftwaalf.eu
And then use this in your afwezigheden.eu/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_URI} !sites/
RewriteRule (.*) /sites/%{HTTP_HOST}/$1 [L]
Related
I'm trying to redirect every request to "https" instead of any call to "example.org/forum/...", but hunderets of solutions did not work and I can't figure out why for example this approach does not work:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/forum/.*$
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://example.org$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/forum/.*$
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://example.org/$1 [R=301,L]
EDIT: I've tried this example now on a domain with just some folders, index.html files and a .htacess file with nothing but these two rules in the root and works like charm!
The point is that I try to achieve this on a domain with a cms underneath, it is a contao installation and there it does not work. I also tried it on a wordpress installation and there it does not work too!
So I think it has something to do with internal redirections, does anyone has a clue!? I can't find such a case on the web...
The RewriteCond directive REQUEST_URI is starting with /, you should make these rules change:
RewriteCond %{REQUEST_URI} !^/forum/.*$
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://example.org/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/forum/.*$
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://example.org/$1 [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomaim.com$
RewriteRule (.*) https://www.yourdomain.com/$1 [R=301,L]
RewriteRule ^$ folder name [L]
It works for me redirect all to https
Foldername is the folder after youdomain.com/foldername
So I'm having this website which is stored inside public_html/www/. Some other domains are stored in -for example- public_html/test/. In public_html I have a .htaccess file with a LOT of redirects in it, which all apply to this website inside /www/ folder. Inside the /www/ folder I have another .htaccess (I don't really know why, my colleague did this and he left me with this without information). Since I have no idea how .htaccess exactly works, I have no idea what to do and in which file.
What I need to do is to redirect domain.nl to https://www.domain.nl (some folders should be excluded, like you can see in the code below - emailtemplates, paymentupdate, autocode, nieuwsbrieven, etc.) But domain.nl is stored inside public_html/www/ folder, so it also needs a redirect to the subfolder (which should not be visible in web browser).
At this moment, in the root .htaccess file is the following:
# Use HTTPS
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.nl [NC]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/emailtemplates
RewriteCond %{REQUEST_URI} !^/paymentupdate_ideal
RewriteCond %{REQUEST_URI} !^/autocode
RewriteCond %{REQUEST_URI} !^/nieuwsbrieven
RewriteCond %{REQUEST_URI} !^/bevestig-aanmelding-nieuwsbrief
RewriteCond %{REQUEST_URI} !^/bevestig-afspraak
RewriteCond %{REQUEST_URI} !^/images/personal
RewriteCond %{REQUEST_URI} !^/uploadify
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Link to subfolder
# RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?www.domain.nl$
RewriteCond %{REQUEST_URI} !^/www/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /www/$1
RewriteCond %{HTTP_HOST} ^(www.)?www.domain.nl$
RewriteRule ^(/)?$ www/index.php?page=home [L]
# Non-www to www
#activate rewrite engine
#RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?domain.nl
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Probably half of this code isn't even necessary, but I have absolutely no clue. The other .htaccess file, within the subfolder /www/, has the following text which I don't really understand (it contains more, but nothing relevant):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.domain.nl/$1/ [L,R=301]
I'm sorry if I sound stupid. I've tried many things copied from internet, but unfortunately everything has its concequences, which results in other problems with our website (links that don't work anymore, such as). I think the reason it doesn't work all the time, is because it's stored in the subfolder and I don't know how to combine all those lines in one like it would work.
Can anybody help me explain how to fix this and what is going wrong at this moment? Because the website is now not redirecting to www. It's just redirecting to https which gives me a security error at this moment (because the SSL is stored on www.). SUPER thanks in advance!
My problem was wrong order of the checks. First, I redirected to https://, but when I did not use www., it did not redirect to https://www OR it redirected to https://www.www. I fixed my problem by re-ordering my rules, like below:
# Non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
# Permanent redirect to https://
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/excluded_folder1/
RewriteCond %{REQUEST_URI} !^/excluded_folder2/
RewriteCond %{REQUEST_URI} !^/excluded_folder3/
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Use subfolder for domain
RewriteCond %{HTTP_HOST} ^(www.)?www.domain.nl$
RewriteCond %{REQUEST_URI} !^/www/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /www/$1
RewriteCond %{HTTP_HOST} ^(www.)?www.domain.nl$
RewriteRule ^(/)?$ www/index.php?page=home [L]
How to redirect with domain
site.com/image/some_symbols
to subdomain
some_symbols.site.com/
I've tried so
RewriteCond %{HTTP_HOST} ^(www\.|)site\.com$ [NC]
RewriteCond %{REQUEST_URI} ^image/(+*)$
RewriteRule ^(.*)$ http://%1.%{HTTP_HOST}/$ [R=301,L]
The %{REQUEST_URI} starts from the / at the beginning; which is why your pattern was not successful.
Better yet, do not rely on another RewriteCond, keeping it simply as:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?site\.com$
RewriteRule ^image/(.+)$ http://$1.%{HTTP_HOST}/ [R=301,L]
I have two domains, autodromodifranciacorta.it and franciacortacircuit.com both pointing to the same website hosted on this IP address: 94.23.64.40.
Now i want all the content to be under one single domain, so i decided to 301 redirect all the traffic from franciacortacircuit.com to autodromodifranciacorta.it
Here is my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Redirect Entire Site to New Domain
RewriteCond %{HTTP_HOST} ^franciacortacircuit\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.autodromodifranciacorta\.it$ [NC]
RewriteRule ^(.*)$ http://autodromodifranciacorta.it/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The redirect is not working and i have no clue why, because the syntax looks correct to me.
The .htaccess file is processed, because if i put a typo in it, i get server error.
Wha'ts wrong with it?
Your second http_host condition is wrong and it never matches if the current host is franciacortacircuit.com, You need to use an OR condition to match against 2 diffrent hosts.
#Redirect Entire Site to New Domain
RewriteCond %{HTTP_HOST} ^franciacortacircuit\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.autodromodifranciacorta\.it$ [NC]
RewriteRule ^(.*)$ http://autodromodifranciacorta.it/$1 [R=301,L]
I'm trying to write a RewriteRule for my .htaccess file. Specifically, whenever a user accesses a specific subdirectory, I would like it to Rewrite to force an HTTPS connection.
For example, whenever someone accesses: http://www.mydomain.com/subdirectory (and any other sub-directories of that "subdirectory").
I'd like it to rewrite to https://www.mydomain.com/subdirectory
I've tried the following, but it appears to create a loop:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.com/subdirectory/$1 [R=301,L]
Also, this .htaccess file is placed in the root of my domain.
Any ideas on how to modify my RewriteRule?
Many Thanks!
I would put this into the domain's root directory:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(subdirectory/.*)$ https://www.mydomain.com/$1 [R=301,L]
This work for me, this allow you to redirect to https a specific folder, just add an htaccess file inside of the folder with the following content:
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Ahh, its a combo of the two. MonoMano - you've omitted the subdirectory in the first part of the RewriteRule, therefore directing ALL traffic to the HTTPS subdomain address. I found that checking for 'off' was more reliable than checking for !=on, dont ask me why!
You'd want to add the subdirectory back in as per Floern's response, see below:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(subdirectory/.*)$ https://www.mydomain.com/subdirectory/$1 [R=301,L]
Add the lines given below to .htaccess file of that subdirectory:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.domain.com/subdirectory/$1 [L,R=301]
Use this if you don't want the address bar to show the subfolder. It will redirect yourdomain.com to yourdomain.com/subfolder but will look like you are still on yourdomain.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?yourprimarydomain.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
RewriteRule ^(/)?$ subfolder/index.php [L]
Try This
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
This will remove www prefix , and force https:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [OR,NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://example.com%{REQUEST_URI} [NE,R=301,L]
RewriteRule ^((?!subdirectory/).*)$ /subdirectory/$1 [L]
Change example.com for you main domain and subdirectory for Sub Directory
Try
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.mydomain.com/subdirectory/$1 [R=301,L]