why none-www redirects to https - web

If I run "http://example.com" or "example.com" it redirects to https://www.example.com. Is there anyway I can stop this and ensure it just redirects to http://www.example.com. It doesn't seem to be anything controlled in the htaccess so I'm not sure where else to look. Here is the current htacess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on
RewriteRule ^/?$ http://%{SERVER_NAME}/ [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The lines:
RewriteCond %{HTTPS} on
(and) RewriteRule ^/?$ http://%{SERVER_NAME}/ [R=301,L]
were added to try and stop the problem but don't seem to do anything.
Thanks

Related

Htaccess causes redirects chain

Recently, we switched from www.example.deto www.example.com/de. Unfortunately some minor and bigger issue occurred with the .htaccess.
Issue
Redirect chain
www.example.de/path redirects to www.example.com/de/path an then to www.example.com/de/path/
How do I remove the unecessary redirect?
Every blog article gets redirected to http and then to https.
https://www.example.de/blog/article redirects to http://example.com/blog/article/ then to https://example.com/blog/article/ and finally to https://example.com/de/blog/article/
The redirect to http only occurs for the blog. The rest off the website doesnt redirect to http.
It seems to me that the htaccess is ignored by requests to the blog. I don`t know what I did wrong!
htaccess www.example.de:
SetEnv PHPRC /home/customer/www/example.de/public_html/php.ini
RewriteEngine on
RewriteRule ^(.*)$ https://www.example.com/de/$1 [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
htaccess www.example.com/de:
SetEnv PHPRC /home/customer/www/example.com/public_html/php.ini
# BEGIN rlrssslReallySimpleSSL rsssl_version[5.1.0]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Possible Solution
Can I add this to solve the Issue with the trailing slash?
RewriteCond %{REQUEST_URI} /(.+)/$
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ https://www.example.com/%1 [R=301,L]

How to make .htaccess redirect to subdomain with parameters

How do I make a redirect from all pages following /react-api, such as:
www.example.com/react-api/workout?id=123
www.example.com/react-api/another-site/?id=321
to:
app.example.com/react-api
and I wan't to keep the folder and parameters.
This is what I have tried:
# 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 %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^react-api/(.*) app.example.com/$1 [R=301,L]
</IfModule>
# END WordPress
But it doesn't work.
Please help
You need to use http:// in your target URL and also change order of your rules and keep redirect rule at the top:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^react-api(/.*)?$ http://app.example.com%{REQUEST_URI} [R=301,NE,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

.htaccess 301 redirecting sub-sub directory URLs to fixed sub dir url

I need to redirect all of the following URLs:
/blog/blog/this-is-an-example-page/
/blog/blog/hello-how-are-you/
/blog/blog/2015/04/29/old-article/
/blog/blog/2014/09/12/
To the following dir:
/blog/
And simply lose the rest of the URL. So, /blog/blog/this-is-an-example-page/ does NOT go to /blog/this-is-an-example-page/, but to /blog/. This is the line in my .htaccess file that should do this, but it doesn't work:
RewriteRule ^blog/blog/(.*)$ /blog/$1 [R=301,L,NC]
This is the full .htaccess file content:
Options +FollowSymLinks
RewriteEngine On
# Force https and www
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.easterisland.travel/blog/$1 [R,L]
# BEGIN WordPress
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
# END WordPress
RewriteRule ^blog/blog/(.*)$ /blog/$1 [R=301,L,NC]
This file is located in the /blog/ dir.
What am I doing wrong? Why is it not working?
You don't need to match against the folder the htaccess file is located in, try :
RewriteRule ^blog/(.+)$ /blog/$1 [R=301,L,NC]
Try this htacess :
Options +FollowSymLinks
RewriteEngine On
# Force https and www
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.easterisland.travel/blog/$1 [R,L]
# BEGIN WordPress
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteRule ^blog/(.+)$ /blog/ [R=301,L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
# END WordPress
Keep redirect rules before other rules and fix your www + https rule:
Options +FollowSymLinks
RewriteEngine On
# Force https and www
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.easterisland.travel/$1 [R=301,L,NE]
RewriteRule ^blog/blog/(.*)$ /blog/ [R=301,L,NC]
# BEGIN WordPress
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
# END WordPress
Make sure to clear your browser cache completely when testing this change.

301 permanent redirect not working (WordPress)

I'm trying to redirect all requests to a preview site to a different site. I'm not sure why this is not working. I'm not being redirected when I click the link.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^site.preview.com$ [NC]
RewriteRule (.*) newsite.com/$1 [L,R=301]
</IfModule>
# 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]
</IfModule>
# END WordPress
Answer is to remove the ! in the RewriteCond as this says only rewrite it if the the url is not equal to site.preview.com but I want it to redirect if that url is entered.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^site.preview.com$ [NC]
RewriteRule (.*) newsite.com/$1 [L,R=301]
</IfModule>
# 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]
</IfModule>
# END WordPress

.htaccess but only from GET variable

I am using wordpress and need to redirect wp-login?action=register to /registration/ page,
first i did
Redirect /wp-login.php http://www.class-world.com/register/
but then it also keeps redirecting logout wp-login.php?action=logout so cant logout at all.
My question is how to only redirect action=register, instead of whole wp-login.php
I tried with following:
RewriteRule ^/wp-login.php\?action=register$ /register/
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^/wp-login.php\?action=register$ /register/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
but no luck
Try this code :
RewriteEngine On
RewriteCond %{QUERY_STRING} ^action=register
RewriteRule ^wp-login\.php$ /register/ [R=301]

Resources