exclude subdomains from .htaccess for wordpress multisite - wordpress

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]

Related

Wordpress redirect subdomain to subdirectory

Hi i have a wordpress site with two subdirectories:
example.com/forum
example.com/shop
I need to display example.com/forum on subdomain like this: forum.example.com, and simmilar with /shop
I try to do this by modyfing htaccess, but no results.
The code i was added looks like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^forum.example.com
RewriteRule ^(.*)$ http://example.com/forum/$1 [L,NC,QSA]
So the whole htacces looks like this:
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]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^forum.example.com
RewriteRule ^(.*)$ http://example.com/forum/$1 [L,NC,QSA]
But this not working.
Also i have redirect my subdomains to subdirectories on the serwer, do i need to copy htaccess to those subdirectories?
Sorry for my bad english

htaccess redirect a page to subdomain

We are trying to redirect a single page from our parent domain to a subdomain:
http://foo.com/calendar
http://www.foo.com/calendar
redirect to:
http://events.foo.com/calendar
Using cPanel redirect, it gives us this:
RewriteCond %{HTTP_HOST} ^foo\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.foo\.com$
RewriteRule ^calendar$ "http\:\/\/events\.foo\.com\/calendar\/" [R=301,L]
However, the redirect is not working.
RewriteEngine On is included at the start of the htaccess file, as it is a WordPress site.
UPDATE:
Here is the entire htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
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]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^foo\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.foo\.com$
RewriteRule ^calendar$ "http\:\/\/events\.foo\.com\/calendar\/" [R=301,L]

Subdomain "m." with Wordpress and. htaccess (Conflict in the rewrite rules in the htaccess.)

I do not usually in the habit of posting , because I always find my answer by searching the forums , but today I came across a real problem !
I have a Wordpress install multisite in a subdirectory of my domain. That is to say, it is at http://mondomaine.com/fr/ .
I wish to make a mobile version in a subdomain "m . " I want my mobile version is available at http://m.mondomaine.com/fr/ .
My host has created the subdomain m that points to the root of the site.
When I want to access a page from my mobile subdomain redirects it necessarily to the homepage /fr/ .
I tried to change my .htaccess , But nothing could be done , or I have a redirect loop , or I have a 404 page.
I suppose that there is a conflict between the rules , but I really tried and tested lots of solutions and I found nothing conclusive.
The original htaccess generated by Wordpress and located in the directory /fr :
RewriteEngine On
RewriteBase /fr/
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]
.htaccess that I modified:
RewriteEngine On
RewriteBase /fr/
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]
RewriteCond %{HTTP_HOST} !^m\.(.*) [NC]
RewriteRule . index.php [L]
RewriteCond %{HTTP_HOST} ^m\.(.*) [NC]
RewriteRule ^(.*)$ http://mondomaine.com/fr/$1 [L,P]
Thank you in advance to those who respond
If mod_proxy is enabled then move last m. rule right at the top, just below RewriteEngine On as this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^m\.(.+)$ [NC]
RewriteRule ^(.*)$ http://mondomaine.com/fr/$1 [L,P]

Forward to www in WordPress multisites

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]

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