I have a Wordpress multisite installed, and would like to understand how the subdomains actually are managed, ie how does my wordpress multisite knows where to find the files/data when a browser request URL user1.domain.com ?
I checked the DNS A record and see only the wild card.
I checked the .htaccess, and it looks as follows:
RewriteEngine On
RewriteBase /
# Protect the htaccess file
<Files .htaccess>
Order Allow,Deny
Deny from all
</Files>
# Protect wpconfig.php
<Files wp-config.php>
Order Allow,Deny
Deny from all
</Files>
# Disable directory browsing
Options All -Indexes
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
so I think the .htaccess does not manage the subdomain, or does it?
so then, how does my wordpress multisite knows where to find the files/data when a browser request URL user1.domain.com ?
Related
First, I am sorry if there are similar threads, but I cannot figure out what is the right approach for the following problem:
I cannot figure out, how to properly change my .htaccess files, so that the following conditions will work:
I have 2 independent WordPress instances under one domain. (Lets say: example.com)
Old instance is hosted here: example.com/old/
New instance is hosted here: example.com/new/
Current behaviour when i access example.com:
When I access example.com, it redirects to the old instance.
Browser is showing: example.com/old
Desired behaviour, when i access example.com:
It Redirects to example.com/new/
Hides the subfolder path (/new) from the url, so that in the address bar only example.com is visible (or any other part except the /new/) in the middle.
My first approach was to add the following line in the /old/.htaccess:
Redirect 301 / https://example.com/new/
But then, it redirected example.com to: example.com/new/old/ which resulted in a 404.
Since the .htaccess files look kind of identical in /old/ and /new/ I cannot figure out, where exactly is defined, that example.com/ is redirecting to /old/ by default.
Here are the .htaccess contents of each instance and root folder:
.htaccess-content / (root)
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
.htaccess-content /old/ (old instance)
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/
RewriteRule .* - [CO=wordpress_test_cookie:WP+Cookie+check:%{HTTP_HOST}:1440:/]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /old/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /old/index.php [L]
</IfModule>
# END WordPress
.htaccess-content /new/ (new instance)
#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /new/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /new/index.php [L]
</IfModule>
# END WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Header always set Content-Security-Policy "upgrade-insecure-requests;"
</IfModule>
Any help is highly appreciated.
Thank you.
You need to use a RewriteRule in your old/. htaccess instead of using Redirect . A RewriteRule can map the request from your old directory to the new directory without a change in URL.
RewriteEngine On
RewriteCond %{REQUEST_URI} !/new [NC]
RewriteRule ^(.*)$ /new/$1 [L]
This should go in htaccess in your /root directory and remember to put this at the top or before other rewriting directives.
Also change "WordPress home URL" and "Site address" by going to settings->general in your WordPress dashboard.
You can use https://example.com as the WordPress home URL and https://example.com/new as your WordPress site address.
Let me know how it works for you.
I have read so many posts on this my head is absolutely swimming and nothing I try seems to work properly. My site was http://www I have changed it in the wordpress settings to https:// (non-www) (I have an ssl certificate installed)
I have an existing .htaccess file.
I cant figure out how to adjust my existing .htaccess to redirect all requests to https:// (non-www) Can someone please give me the full code simply of what my htaccess should be ?
This is my existing htaccess file:
# 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
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php70” package as the default “PHP” programming language.
<IfModule mime_module>
AddType application/x-httpd-ea-php70 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
<Files 403.shtml>
order allow,deny
allow from all
</Files>
according to this post you can change your .httaccess file to redirect:
http://example.com
http://www.example.com
https://example.com
to
https://example.com
using
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
simply add this code after #end wordpress in your .htaccess file.
after saving the .htaccess file remember to save your permalink structure in settings->permalink.
I am prepping a site for launch. I'm still learning how to work with .htaccess, and I'm having some trouble. The new wordpress site is in the /wpfiles directory. Trying to visit /wpfiles gets redirected to /main. It seems that accessing the index.php file in /wpfiles triggers the rewrite rule below, but accessing any other file or directory in /wpfiles doesn't.
I would like to open up the /wpfiles directory so that I am able to review the site and send it to the client. Here is the existing .htaccess file from the public_html directory.
RewriteOptions inherit
RewriteEngine on
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName siteurl.com
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ "http\:\/\/siteurl\.com\/main\/" [R=301,L]
My /wpfiles .htaccess file is as follows:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wpfiles/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wpfiles/index.php [L]
</IfModule>
# END WordPress
What might I need to adjust in order to only exempt /wpfiles/index.php from the rewrite rule?
Thanks in advance for your help!
I am server admin which hosts many sites. One of them is running wordpress. If password protect wp-admin/ through cPanel, when browse to site0.com/wp-admin, it falls into a redirect loop.
I found out that this behavior is because wp-admin redirects to wp-login.php if not logged in and if is password protected, somehow authentication rules in .htaccess of wp-admin conflicts with rewriterule(s) in global .htaccess (in public_html) and so redirection goes infinitely. Then if I comment rewriterule(s), login comes up, however inner pages of WordPress no longer work.
public_html/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
public_html/wp-admin/.htaccess:
AuthUserFile "/home/paraf/.htpasswds/public_html/wp-admin/passwd"
AuthName "wp-admin"
<Files admin-ajax.php>
Order allow,deny
Allow from all
Satisfy any
</Files>
AuthType Basic
require valid-user
Protecting wp-admin by htaccess is unnecessary I think, so maybe you are solving problem that isn't there. You can still access wp-login.php directly.
I have researched this and unfortunately all I can find is general advice on htacesss and pass wording or general htaccess to redirect etc. None of them are what I am after here.
To sum up, we run a set of blogs all using the WordPress Multisite functionality.
All these files etc and info in the database are referenced by an ID and as such the site does not live in a folder.
I want to restrict one folder with a htaccess that our company uses to allow access to its users.
Normally I would drop that file in the folder and job done.
However, as mentioned there are no physical folders and so I need to somehow add this to the existing htaccess file that WordPress uses to handle everything.
Here is the htaccess file as standard:
RewriteEngine On
RewriteBase /
#uploaded files
RewriteRule ^(.*/)?files/$ index.php [L]
RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
# deperectaed after upgrade to v. 3.0 RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]
RewriteRule ^(.*/)?files/(.*) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ $1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
<IfModule mod_security.c>
<Files async-upload.php>
SecFilterEngine Off
SecFilterScanPOST Off
</Files>
</IfModule>
What I need to add is the following:
AuthName "You must be a valid user"
AuthType Basic
require valid-user
But I only need it to work on one site, say site id=2 for now. I would possibly like to add sites to this later.
Any help will be greatly appreciated.
Cheers
You can use the filesMatch directive to protect the directories. For a site at the path of /foo/ the following should work:
<filesMatch "^foo.*">
AuthName "You must be a valid user"
AuthType Basic
require valid-user
</filesMatch>
To Make sure the filesMatch directive works, try:
<filesMatch "^foo.*">
order allow,deny
deny from all
</filesMatch>