.htaccess redirect to same subfolder - wordpress

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>

Related

subdirectories blog post wordpress not shown in laravel

I'am using wordpress as my blog in my laravel site. The wordpress blog are placed in subdirectories so that the domain of the wordpress is mydomain.com/blog.
I've tested it in my localhost and it works perfectly. But when i deployed it on server the site can show the homepage of my blog. But it can't display the blog's page ex. domain.com/blog/contact (404 Page not found) .
I've done several steps like changed the .htaccess and define the WP_HOME /WP_SITEURL but it still doesn't works to show my blog post .
Here is my wordpress .htaccess
<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>
And here are my laravel site's .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/blog/ # <=== NEW LINE!!!!
# 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}]
what am i doing wrong here?

Installing a second WordPress instance in a subfolder issue

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/

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>

WordPress - redirect all pages to other domain and exception homepage and wp-admin

I need help with WordPress redirect. I think, that the simplest way is make this with htaccess file.
I want 301 redirect all pages from my site www.domain.com to subdomain web.domain.com, but I want have exception for homepage www.domain.com and for wordpress admin in www.domain.com/wp-admin/... and www.domain.com/wp-login.php
I have the basic wordpress htaccess settings:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
You can do:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule !^(wp-admin(/.*)?|wp-login\.php)?$ http://web.domain.com%{REQUEST_URI} [L,NC,NE,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Thanks for your help - I find, that I need both wp admin so I make this settings:
RewriteEngine on
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !/wpinstall(/.*)$
RewriteRule (.*) http://web.domain.cz/$1 [R=301,QSA]
And I install wp to subfolder wpinstall

Redirect directory (but not subdirectories) to another directory

How do I redirect a directory to the root of a site? Provided that:
the root of the site is actually not the root of the domain. ex: it should redirect to 'www.example.com/website', not to 'www.example.com'
don't redirect subfolders. ex: it should redirect 'www.example.com/website/portfolio' to 'www.example.com/website', but it shouldn't redirect 'www.example.com/website/portfolio/project-name'.
It's a WordPress site and it's already working with the following rules:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /website/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /website/index.php [L]
</IfModule>
# END WordPress
Thanks in advance!
You can do:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /website/
RewriteRule ^portfolio/?$ /website/ [L,R]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /website/index.php [L]
</IfModule>

Resources