Forward to www in WordPress multisites - wordpress

I have a WordPress multisite (using subfolders, not subdomains) in the format domain.com. For reasons of consistency and better SEO, I'd like to forward it to www.domain.com.
I've tried putting this code into .htaccess but I get a redirect loop:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# this is the code I added to forward to www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
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]
I'm pretty sure my domain is set to without www in the WordPress settings but it won't let me see that any more now I have a multisite.

I would try first not using htaccess redirect and remove the www redirect you have. Then edit your wp-config.php and change the DOMAIN_CURRENT_SITE to be your www domain. This way wordpress will handle the redirection.
Or you can try the htaccess method, but you might have some order problems, I believe with MU, the redirect needs to be the first thing. Replace domain.com with your real site.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
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]

Related

exclude subdomains from .htaccess for wordpress multisite

I have a plesk server and its configured to launch Roundcube on webmail.domain.com . Also I configured my Wordpress as a multi-site to react as with anysubdomain.domain.com, but it stops the webmail subdomain to work. How do I exclude that subdomain (webmail) from been cached by Wordpress ?
This is my .htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
to EXCLUDE (sub)domains in your ".htaccess" - file, you would use something like:
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^webmail\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

WP Site Network htaccess redirect to https

I use wordpress with a Site Network. Since I wanna use different kinda themes on the same domain it's necessary. To make this work I needed to change my htaccess file into what WP ordered me to. But then my redirection to https didn't work anymore.
I have the following htaccess code:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
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]
I wanna add a redirection to https:// w w w. for any access to the website.
Anything I do, in the end one of the former rules aren't working anymore. And afterwards the Wordpress Network Sites don't work anymore.
Any suggestions?
You need to keep redirection rule before your your WP rule:
RewriteEngine On
RewriteBase /
# http to https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
Also don't forget to change permalink setting in WP to use https for your blog/site

Force HTTPS on entire site except 1 directory

I have this .htaccess file right now:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
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]
It redirects everything on my site to HTTPS, which is great, however, I want the /example directory to never be in HTTPS, I want it to always be HTTP.
How could I accomplish this while having the rest of the site be HTTPS?

Wordpress network .htaccess issue

I have a Wordpress network setup but currently there is only one subsite with the url
/psychology
In the future there will be addition sites with
/md
/vet
but for the time being there will only be /psychology
What I want to do is have a rewrite rule in my htaccess that when a user visits the root of the site (/) it actually loads the /psychology site.
I tried adding a line like this to my htaccess
RewriteRule (.*) psychology/$1 [R,L]
but it broke the site. here is my current htaccess (basically the wordpress default for a network install)
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /ASKanALLY/
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress
Any ideas?
You need to add the base to the RewriteRule destination. And add a condition so you don't get a redirect loop.
Adding these two lines after RewriteRule ^ - [L] should work:
RewriteCond %{REQUEST_URI} !^/ASKanALLY/psychology ## Not already viewing a psychology URL
RewriteRule ^(.*)$ /ASKanALLY/psychology/$1 [R,L] ## Redirect to psychology
Here's the complete example:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /ASKanALLY/
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} !^/ASKanALLY/psychology ## Not already viewing a psychology URL
RewriteRule ^(.*)$ /ASKanALLY/psychology/$1 [R,L] ## Redirect to psychology
RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
</IfModule>
Your RewriteRule didn't work because it was matching all URLs, including ones to /psychology/foo. I'm guessing you don't have a .htaccess file under /psychology?
Try this - it'll rewrite just the root.
RewriteRule ^/$ psychology/ [r=301,L]

Prevent subpages from redirecting to the root URI

I'm having a minor but annoying issue with a site running WordPress 3.1.4 Multisite.
Navigating to the URI of a subpage without the "http://www" such as "abetterworldbydesign.com/2011-conference/" results in a redirect to the root "http://www.abetterworldbydesign.com".
The intent is for "abetterworldbydesign.com/2011-conference/" to redirect to "http://www.abetterworldbydesign.com/2011-conference/".
.htaccess file below (it's specific stuff for WordPress Multisite).
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# END WordPress
Try adding this
RewriteCond %{HTTP_HOST} ^abetterworldbydesign.com
RewriteRule ^(.*)$ http://www.abetterworldbydesign.com/$1 [R=301,L]
at the very top, just after RewriteEngine On.

Resources