Installing a second WordPress instance in a subfolder issue - wordpress

I have a shared Linux hosting on which I want to host 2 website.
In /public_html/ I have hosted example.com and on /public_html/example2/ I have hosted example2.com
.htaccess of example.com
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
# 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
#Custom Error Pages
ErrorDocument 403 https://www.example.com/error-403/
.htaccess of example2.com
# 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
#Custom Error Pages
ErrorDocument 403 http://www.example2.com/error-403/
I want to access both the website separately with www version i.e.
example.com as https://www.example.com/ (has SSL it's in main directory)
example2.com as http://www.example2.com/ (do not have SSL and it in sub directory)
Please Note: I have setup site_url and home_url and above given URL in WordPress General settings.
Problem that I'm facing is
When I access example2.com it is taking me to https://www.example.com/example2/
So after reading this answer, and I changed my .htaccess of example.com to
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# if request is not for the /example2/
RewriteCond %{REQUEST_URI} !^/example2/ [NC]
# otherwise forward it to index.php
RewriteRule . /index.php [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
</IfModule>
# END WordPress
So now example2.com is accessible but permalink is not working so when I try to reset it, it is deleting the content of my example2 .haccess file and redirecting me to https://www.example.com/example2/.
Can any one help me out here?
I also tried this with no luck Configuring WordPress .htaccess to view subfolders.

I think that htaccess for example 2 should be like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /example2
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#Custom Error Pages
ErrorDocument 403 http://www.example2.com/error-403/

Related

.htaccess redirect to same subfolder

My problem is the following: My company shares hosting with others, and we have the subdomain inside a "public_html" folder. I can enter the index of my page perfectly, that is in www.principal.com/mypage it enters perfectly.
The problem is when I redirect to pages within my subdomain, they redirect to the 404 Not Found of the main page, that is to say www.principal.com/mypage/new 404 Not Found page of principal.com
The main / public_html / .htaccess file is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
The file public_html/mypage/.htaccess is
<FilesMatch ".(phtml|php|PhP|php5|suspected)$">
Order Allow,Deny
Allow from all
</FilesMatch>
The file public_html/mypage/public/.htaccess is
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
I must clarify that my subdomain worked perfectly until a few days ago, since March that it worked very well.
Wordpress is the main page of the domain, my page in the subdomain is with the Laravel framework.
So, I redirect from Laravel to Laravel whit
Route::group([
'middleware' => 'auth'],
function(){
Route::get('/onepage', 'HomeController#one');
Route::get('/twopage', 'HomeController#two');
});
Your problem is because the directives in the root level .htaccess are used even something might be directed to the site in the subfolder. Try something like this in public_html/.htaccess, to exclude requests sent to the subfoler:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_URI} !^/autorizaciones/.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
I solved it
I changed The file public_html/mypage/.htaccess is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /MYPAGE
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

limitinternalrecursion wordpress permalinks

I have an NGINX server that is proxy_pass-ing any urls that end in /blog to an IP address where I have a WordPress instance running with Apache.
The issue I am having is that when I enable permalinks I get a LimitInternalRecursion error. When I don't enable permalinks everything works as expected and I can access all of my blog pages through the proxy.
Here are the contents of the .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
EDIT:
I found out the rewrite rule provided by WordPress needed to be changed to:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php/$1 [L,QSA]
</IfModule>

htaccess external domain to new domain

I have asked my domain host provider to point a website to my public_html folder. but now I have been told the if I need this other domain to redirect to a particular url on my primary domain website, I would need to do it in the htaccess file. At the moment I have researched and this is what my htaccess looks like without any luck!
# Switch rewrite engine off in case this was installed under HostPay.
RewriteEngine Off
SetEnv DEFAULT_PHP_VERSION 5
DirectoryIndex index.cgi index.php
# 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
RewriteCond %{HTTP_HOST} ^otherdomain.org.uk
RewriteRule ^(.*)$ http://www.primarydomain.org/blog/$1 [R=permanent,L]
The above does not redirect my otherdomain.org.uk to the blog page on my primarydomain.org/blog. Please note that my primarydomain.org/blog is a wordpress website page.
Keep redirect rules before your WP rules.
Have your rules like this:
# Switch rewrite engine off in case this was installed under HostPay.
RewriteEngine Off
SetEnv DEFAULT_PHP_VERSION 5
DirectoryIndex index.cgi index.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^otherdomain.org.uk
RewriteRule ^(.*)$ http://www.primarydomain.org/blog/$1 [R=permanent,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

wordpress http to https redirect loop

I am trying to force my site to load in HTTPS. I can create a redirect in PHP which works for PHP files, but I want all requests forced to HTTPS - JS, CSS, Images, etc.
Here's what I have in my .htaccess:
ErrorDocument 401 default
# 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
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
I have tried various methods of this by placing the redirect in different locations and such, but everything seems to make this into a redirect loop. Any ideas what I could do to fix that?
Thank you.
Keep your http to https rules before internal WP rule:
ErrorDocument 401 default
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=302]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Make sure WP's home URL and site URL also have https in permalink settings.
Set a 301 permanent redirect which is more SEO friendly. Already tested:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect all traffic to https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# Wordpress rules
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Wordpress : redirect url to a subdomain

I have just hosted a wordpress website on godaddy .
I am having a situation .
I have a website www.example.com/cnI want when someone open this page this page should redirect to a sub domain cn.example.com .
I am hosting wordpress app first time kindly do let me know how can I do that .I am Python Guy I don't know about htaccess
I tried using header('location:cn.example.com') in the index.php file but the problem is cn.example.com and example.com/cn both pointed to the same wordpress app . So I am getting problem .
Please help me to figure out this problem .
*Updated Htaccess *
RewriteCond %{REQUEST_URI} ^/_dm/s/ [NC,OR]
RewriteCond %{REQUEST_FILENAME} !\.(jpg|gif|png|css|js|txt|ico|pdf|bmp|tif|mp3|wav|wma|asf|mp4|flv|mpg|avi|csv|doc|docx|xls|xlsx|ppt|pptx|zip|rar|tar|gz|dmg|iso)$ [NC]
RewriteBase /
RewriteRule ^(.*)$ http://mobile.example.com/ [R,L]
##END MOBILE
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (?!cn.example.com)
RewriteRule ^cn/?$ http://cn.example.com/ [R=301,L]
</IfModule>
<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
# 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
Thanks
Assuming you are letting Wordpress load from the differing hostname, you can handle the rewrite by having the following in your .htaccess file found in the root of your Wordpress install:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (?!cn.example.com)
RewriteRule ^cn/?$ http://cn.example.com/ [R=301,L]
It will match /cn or /cn/ exactly from any host that is not already cn.example.com (prevent looping), and redirect to http://cn.example.com using a 301 HTTP response.
You can test these rules here: http://htaccess.madewithlove.be/

Resources