Add a RewriteRule for WordPress multisite - wordpress

I have a brand new WP multisite network (v 3.5.1) on sub-directories. I'm getting an error with the images, where the subsites won't display them properly, but they are being uploaded correctly. I'm pretty sure all I need to do is add the correct RewriteRule to the .htaccess file in the main site, as such:
When an image is called from anywhere in the site, the URL is: example.com/subsitename/assets/sites/#/imagename.jpg. I want to change it so that the image actually pulls from: example.com/assets/sites/#/imagename.jpg, where subsitename, #, and imagename.jpg are all variables.
It seems like this should be really simple, but I'm having a hard time finding the right syntax or an example of someone else who has solved this issue. Does anyone know the proper RewriteRule I would add?
My current .htaccess file contains this:
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]

Try this instead:
# BEGIN WordPress
<IfModule mod_rewrite.c>
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]
</IfModule>
# END WordPress

Related

301 status redirect code

I'm a novice with a wordpress website. I ran it through a seo checker and was told that my site has a 302 code rather than a 200 code, and that this is a critical error.
After googling I found an article instructing me to go to the the .htaccess file.
I opened the file, and found below:
Options -Indexes
# BEGIN WordPress
<IfModule mod_rewrite.c>
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).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress
Should I just delete the link with the 301 code or change to 200?
Thanks in advance for any assistance or insight. I hope the question makes sense.
If the .htaccess is corrupted (by a plugin or otherwise) you can try and replace it. From the looks of your existing file, you're using a WordPress multi-site installation. You can try replacing the current .htaccess in the subfolder with the following:
WordPress 3.5 and up
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]
WordPress 3.0 through 3.4.2
# 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

Changed sub-site path and facing 404

I was running a multi-site on www.madeinindia.club i have made a sub-site with www.madeinindia.club/work-space and now i changed the path to www.madeinindia.club/karmabhoomi but it is not accessible now. both URL showing 404
Note: I have already changed the same URL one time but then the new url worked.
htaccess file
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).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
Also posted on WordPress Developer

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]

Wordpress Post Links With Wrong Day

I am having a strange issue with a new multi-site wordpress installation. This is installed on a Magento website.
I can see my blog and go into the admin area just fine. However, when I click on a post I get a 404 error. If I change the day in the url it will work.
Example: If the link takes me to mysite.com/dev/devsite/default/blog/2013/11/11/hello-world/ I get the 404. But, if I manually change the day in the url to mysite.com/dev/devsite/default/blog/2013/11/12/hello-world/ I can see the post.
Here is my .htaccess file that the multi-site wordpress told me to use.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dev/devsite/wordpress/
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]
</IfModule>
Any idea why this is?
I also have a WP MultiSite installation under my main website. Here's the .htaccess code used by my site.
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]
Try using this instead of your ones. There is a ending too in your code, I think you copied the code wrong way.

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