1

This is a Wordpress related question, because the problem came from a multi-install Wordpress. But it's also related to serverside, with .htaccess

My problem is : when a user type my URL without WWW, it get him/her to an submission URL, inviting him/her to log-in. From https://mister-tea.fr to an URL like this https://www.fixie-lille.fr/wp-signup.php?new=mister-tea.fr instead of https://www.mister-tea.fr

I really don't want it, I just want that the user is redirected to the same domain, and the same URL with WWW.

My main domain is https://www.fixie-lille.fr (Fr website)

The rule could work :

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^fixie-lille.fr$
RewriteRule (.*) https://www.fixie-lille.fr/$1 [R=301,L]
</IfModule>

But it breaks other website.

I tried using some rules in .htaccess, but does not seems to work. All my websites use WWW domains and are not available without WWW.

Beside that, I use this rule to redirect user between http and https

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Does the following rule could have a bad interference ?

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

Beside that, everything works fine wtih several Wordpress in just one install.

Thanks per advance, I'm at your disposal to answer further questions

1 Answer 1

0

Since you have multiple domains you can't include the domain in the redirect itself to create a one-size-fits-all generic redirect (which is what I assume you are trying to do). You also need to ensure that the directives are in the correct order.

Since all your sites use the www subdomain then try the following instead. However, this assumes you don't have any other subdomains.

RewriteEngine On

# non-www to www (and HTTPS)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [R=301,L]

# HTTP to HTTPS 
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# WordPress directives follow...

The non-www to www redirect now tests if the requested host does not start www. And if not, simply prepends it.

No need to repeat the RewriteEngine directive and no need for the <IfModule mod_rewrite.c> wrappers on your custom directives.

With regards to your HTTP to HTTPS redirect, there's no need to capture the RewriteRule pattern if it is not being used in the substitution. ie. When using %{REQUEST_URI} instead of a backreference.

As always, clear your browser cache before testing.

2
  • Did you get anywhere with this?
    – MrWhite
    Commented Jun 27, 2018 at 22:20
  • Many thanks for your answer. I was AFK from several days ... sorry! I'll try it this evening or tomorrow. Commented Jun 28, 2018 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.