I want to redirect my website to https://subdomain.domain.com in my .htaccess file.
Redirects:
http://subdomain.domain.com => https://subdomain.domain.com
http://www.subdomain.domain.com => https://subdomain.domain.com
https://www.subdomain.domain.com => https://subdomain.domain.com
https://subdomain.domain.com => no redirects
This should do it…
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
First rule redirect all www to https://subdomain.domain.com, second all http to https://subdomain.domain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule (.*) https://subdomain.domain.com/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://subdomain.domain.com/$1 [R=301,L]
Related
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]
I am trying to create a .htaccess file with the following rules:
http://www.example.com/test => https://example.com/test
http://test.example.com/test => https://test.example.com/test
https://www.example.com/test => https://example.com/test
This is my current .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.nebla.co.uk$ [NC]
RewriteRule ^(.*)$ http://nebla.co.uk/$1 [R=301,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Howerver this causes some odd behaviour:
http://www.nebla.co.uk/ => https://nebla.co.uk/public_html
It also causes a redirect loop on subdomains.
I managed to fix my behaviour by instead of using
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.nebla.co.uk$ [NC]
RewriteRule ^(.*)$ http://nebla.co.uk/$1 [R=301,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
I changed $1 to %{REQUEST_URI} like:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.nebla.co.uk$ [NC]
RewriteRule ^(.*)$ http://nebla.co.uk/%{REQUEST_URI} [R=301,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
I want to make my homepage to redirect to non https if it https
if https://example.com will redirect to http://example.com
and i want to make directory with ssl (just directory using SSL)
if http://example.com/directory wil redirect to https://example.com/directory
I'm use this :
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
but it just show loop
RewriteEngine On
RewriteCond %{HTTPS} ^on$
RewriteCond %{REQUEST_URI} !^/dir
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} ^off$
RewriteCond %{REQUEST_URI} ^/dir
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I just changed my website http to https. I'll already redirected http to https version. I also want to redirect www version to non www.
So far couldn't succeed it.
http://www.domain.com => https://domain.com
https://www.domain.com => https://domain.com
Here is the .htaccess file;
<ifModule mod_rewrite.c>
RewriteEngine On
redirect 301 /makale /sozluk
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)\.[\d]+\.(css|js)$ $1.$2 [L]
RewriteCond %{HTTPS ^www.sporapp.com$ [NC]
RewriteRule ^(.*)$ https://sporapp.com/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]
</ifModule>
Thank you.
You should remove this bit:
RewriteCond %{HTTPS ^www.sporapp.com$ [NC]
RewriteRule ^(.*)$ https://sporapp.com/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
And add this just under the RewriteEngine On:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.sporapp\.com$ [NC]
RewriteRule ^(.*)$ https://sporapp.com/$1 [R=301,L]
You need to have the redirecting happening before you rewrite, otherwise the request gets changed before it gets redirected.
Also, you have mod_alias directives which will interfere with the rewrite to /index.php:
redirect 301 /makale /sozluk
Should be:
RewriteRule ^makale/(.*)$ /sozluk/$1 [L,R=301]
I need to do the following Redirect using .htaccess
http://example.com => https://example.com/subdirectory
http://www.example.com => https://example.com/subdirectory
https://example.com => https://example.com/subdirectory
https://www.example.com => https://example.com/subdirectory
but i do not want to show sub directory in address bar the url should be https://example.com my site files lives in sub directory but i need to hide it in address bar for every request.
Try these rules:
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !=example.com
RewriteRule ^ https://example.com%{REQUEST_URI} [L,R=301]
RewriteRule ^$ subdirectory [L]
How about this (building on Gumbo's answer):
RewriteEngine On
# Redirect direct subdirectory/ request to main domain
RewriteCond %{THE_REQUEST} ^(POST|GET)\s/subdirectory
RewriteRule ^subdirectory/?(.*)$ https://example.com/$1 [R=301,L]
# Redirect www/non-https to https://example.com
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !=example.com
RewriteRule ^.*$ https://example.com/$0 [R=301,L]
# Redirect (internally) to subdirectory/
RewriteCond %{REQUEST_URI} !^/subdirectory/
RewriteRule ^.*$ subdirectory/$0 [L]