I'm unable to change .htaccess file for wordpress multisite - wordpress

I tried to search this question, but I haven't found the solution. So just want to ask here.
It's very strange that when I manually changed .htaccess file for WordPress multisite as below via SSH on my server, the file will automatically changed back to the default content if I refresh the website in the browser.
I just used vi .htaccess SSH command to modify it, after I modified, I did nothing changed in WordPress admin and I tried to deactivate all the plugin.
The permission of .htaccess is 644.
I don't know the reason. It would be appreciated if you can give me some help.
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]
After I refresh the homepage, it will changed back to
# 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

Finally I fixed this issue. Just put the solution here for the people who has the same problem.
I've upgraded wordpress to the latest version, but I forget to upgrade the whole network, that's it, so stupid mistake.

WordPress changes .htaccess file itself - if it has write permission and you are using pretty links. I suggest adding your rules before original WordPress rules
... your rules ...
# BEGIN WordPress
... original rules ...
# END WordPress
As far as I remember WordPress does search for that comment lines. Bellow text is taken from WordPress source code:
Inserts an array of strings into a file (.htaccess ), placing it between
BEGIN and END markers. Replaces existing marked info. Retains surrounding
data. Creates file if none exists.

Related

Wordpress/OpenLiteSpeed Cannot Publish

My server is Ubtuntu 18.04, OpenLiteSpeed, and Wordpress. With all plugins disabled, and using the default theme we are unable to publish or update posts/pages. This question looks similar to a lot of other ones but none of their solutions are working for me. My understanding of this issue is that maybe our htaccess file isn't being respected by OpenLiteSpeed, even though it is configured to do so. I have not edited the .htaccess file at all. Here are its contents:
# BEGIN LSCACHE
# END LSCACHE
# BEGIN NON_LSCACHE
# END NON_LSCACHE
### Forcing HTTPS rule start
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
### Forcing HTTPS rule end
# 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
I also get 404 error messages in the console for urls in this path: https://example.com/wp-json/wp/v2/*
I have tried updating the permalink structure multiple times to no avail, unless I add index.php to the structure. For example https://example.com/index.php/%postname%/. This allows us to visit posts, update them, etc.
It's great that we can have it working, but that index.php in the URL is just so darn ugly. What do I need to do to get rid of it?
If you are using rewriterule tab in webadmin console, instead of .htaccess
you will need to change the rule
from
RewriteRule ^index.php$ - [L]
to
RewriteRule ^/index.php$ - [L]
save and restart it.
there is slightly difference for rewrite rule when you place it in different place, mostly a forwarding slash like above one.

Wordpress Multisite with Subdirectories issue

I'm trying to set up a WordPress Multisite using subdirectories and I get a problem.
After I set up a Multisite in admin panel, following instructions, I edited two files on my server, 'wp-config.php' and '.htaccess'.
My .htaccess file looks like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
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]
</IfModule>
# END WordPress
After that I updated page and here's how they look like:
Site Page
In console there's a whole bunch of
"Failed to load resource" errors
Somehow it tries to load all the files from 'localhost' rather than from server. How can I fix this problem?
I resolved this issue by changing values in 'wp-options' table from 'localhost' to actual site domain.

Wordpress htaccess not working with subdirectory

i have directoryoffering-pages in my domain
offering-pages/.htaccess code is
# 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
i access dashboard of wordpress and only the home page of my website.
when i go to other page like http://domain/offering-pages/offerings-for-students/ it display the content of domain/index.php
Try this script and change domain and subdomain according to their names and also post wordpress related question to wordpress.stackexchange
RewriteEngine On
# rewrite subdomains to separate folder
RewriteRule ^subdomain/ - [L]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$
RewriteRule ^(.*)$ subdomain/$1 [L]
# or if you want to rewrite sub.domain.com/test to /subdomain/sub/test
#RewriteRule ^(.*)$ subdomain/%1/$1 [L]
# force www
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R]
# BEGIN WordPress
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./index.php [L]
# END WordPress
Did you install Wordpress in the offering-pages directory? If so, you need to change index.php to point to your directory where Wordpress is installed.
From:
require(dirname(__FILE__) . '/wp-blog-header.php');
To:
require(dirname(__FILE__) . '/offering-pages/wp-blog-header.php');
SOLVED!!!
The top site's custom Permalinks (anything other than "Plain") clash with the subdirectory site's custom Permalinks (anything other than "Plain").
Both cannot be set to be custom (without a complicated solution).
To fix (and not get "Invalid JSON response" when modifying or creating Posts and Pages), simply delete the top site's .htaccess file (in the root directory usually under public_html).
And to prevent future clashes, go to the top site's site Settings > Permalinks in WordPress and change the setting to Plain, delete any Category and Tag Base, and click SAVE. When you click SAVE, a new .htaccess file is created or the old one is overwritten for that directory (and Plain actually means an empty .htaccess file or no setting).
This means that you won't be creating pages and posts with pretty URLs from the top site (for that specific site you'll have to use an auto-generated post or page url like example.com/?p=123 instead of example.com/postname).
Antonio Robateau

How to use mod_rewrite without clashing with Wordpress

So I have Wordpress installed, let's call the domain test.com. The .htaccess that wordpress created in the default directory (the one that is one level above wp-content) is
# 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
I want to add another rule, which if triggered, should case Wordpress to not rewrite. So for instance, suppose I want test.com/nochange to redirect to test.com/script.php, instead of doing the normal Wordpress redirects. Normally the .htaccess for this would be
RewriteRule ^nochange$ ./script.php [NC,L]
But what happens is that Wordpress ends up running anyways, and of course a 404 not found occurs. If I removed the Wordpress .htaccess components, everything works. What do I do to get them to work together?
Ah, I just needed to use the END tag.

.htaccess permanent redirect to www

I have a wordpress instalation that is not redirecting urls not starting with www.
Example: http://example.com/dir/ doesn't send to http://www.example.com/dir/ instead goes to http://example.com/
How do I change the .htaccess below to always redirect to the page either using www or not?
# 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).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
# END WordPress
You should not have to modify your .htaccess; actually I would not recommend it.
Sounds like you simply have your values for WordPress address and Site address set correctly in your admin console in the Settings > General section:
Another option is to add the following 2 lines somewhere within your /wp-config.php file but before require_once(ABSPATH . 'wp-settings.php'); (and be sure not to use a trailing slash):
define('WP_HOME',"http://www.example.com/dev");
define('WP_SITEURL',"http://www.example.com/dev");
I prefer this approach because I like to keep my configuration options in code whenever possible since it is easier to maintain that way than configuration options stored in the database.
Hope this helps.
-Mike
P.S. Next time you have a WordPress question, consider asking over at StackOverflow's sister site WordPress Answers? Lots of WordPress enthusiasts over the to help out.
I got the correct answer from webmasters.stackexchange.com. This works perfectly! Thanks Ruel for pointing me to webmasters.stackexchange.
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
More like a question for http://webmasters.stackexchange.com
Well anyway, if you are using cPanel, you can do a wildcard redirect from Redirects under Domains category.
But if not, try this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com[nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
Works perfectly. Put this at the top of wp-config.php file:
define('WP_HOME',"http://www.example.com/dev");
define('WP_SITEURL',"http://www.example.com/dev");

Resources