I am trying to redirect the URL of webroot folder ie,
https://test.example.com/ to https://www.example.com/test
where test => webroot folder.
I have tried redirection in webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
Redirect 301 /http://test.example.com http://example.com/test
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
also tried the following one :
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^https://test.example.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/test/ [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Please help me to solve this..
Try with below,
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(.+)\.example.com
RewriteRule ^ https://www.example.com/%1%{REQUEST_URI} [L,R=301]
This will work:
<IfModule mod_rewrite.c>
RewriteEngine on
Redirect 301 / http://example.com/test/
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Related
this don't work true, i get many redirects from shop and university
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
#RewriteCond %{REQUEST_URI} ^/shop$ [NC]
RewriteRule ^(shop/.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /shop/
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(university/.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /university/
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^(shop/.*)$ [NC]
RewriteCond %{REQUEST_URI} !^(university/.*)$ [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
How do I make the right redirects?
You can use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(shop|university)(/.*)?$ https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
RewriteCond %{HTTPS} on
RewriteRule !^(shop|university)(/.*)?$ http://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
</IfModule>
I have tried following;
If a user try to access my website http://test.com it will redirect to https://test.com but if a user try accessing internal page like http://test.com/test1 it doesn't redirect to https. I have tried following code in my .htaccess file.
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Full .htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</IfModule>
Instead of testing for !on test for off -
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Currently my htaccess file redirects non-https requests for all of my subdomains to https... except for www requests. I.e. http://subdomain.example.com gets redirected to https://subdomain.example.com (this is correct) but www.subdomain.example.com get redirected to https://www.subdomain.example.com (not correct). Here's my .htaccess code:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Trying to redirect to https
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Try changing this:
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
to
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^(?:www\.|)(.+\.example\.com)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
I have switched from http to https, but now I am getting duplicate content. My .htaccess is:
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I want to redirect homepage and all page/post to https. I have tried all methods, but no luck.
The page isn't redirecting properly. Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
No one worked.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.rancahpost.com/$1 [R,L]
This:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
This:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
This
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.rancahpost.com/$1 [R=301,L]
This:
RewriteCond %{HTTPS} on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]
This:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
This:
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
How can I redirect all http traffic to https?
I couldn't find the solution for "non-www" to "www" domain redirection. I have tried the following :
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301]
# Remove index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
</IfModule>
So, how can I redirect, for example domain.com or www.domain.com to http://www.domain.com ?.
Something like should work :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Here is what should help you:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
Can you try this ?
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
Seems apache mod_rewrite module is not enabled. So Make sure the Apache module mod_rewrite is enabled on your web server.
Try again this and see..It must work.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
See here - http://iyngaran.info, It is working. So no problem with the rule
How To Create Temporary and Permanent Redirects with Apache click hear
To automatically add a www to your domain name:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
or
.htaccess To Redirect URLs
To use htaccess to redirect URL just copy and paste the snippet below and replace example.com with your domain.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
More info true ans
Redirecting non-www to www with .htaccess