404 when WordPress is in a subfolder - php

I know this question often comes up but none of the answers is satisfactory for me. I tried everything I could find on the web nothing works.
1 - I installed my Wordpress in a sub folder /folder/wp.
2 - I moved .htaccess and index.php to the root ( given by WordPress )
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /folder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /folder/index.php [L]
</IfModule>
# END WordPress
3 - I changed index.php like this:
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp/wp-blog-header.php' );
4 - I changed WordPress url: http://localhost/folder/wp
5 - I kept site url: http://localhost/folder
Without Permalinks, everything works.
As soon as I turn on permalinks, I have a 404
There are some things I do not understand:
1 - Why keep index.php and .htaccess in the sub folder?
2 - Some say to add /wp in RewriteBase and RewriteRule in .htaccess at the root, but it does not change?
I read dozens of Post and nothing works for me. Has anyone ever faced this problem?
thank you very much

Something that is not thought is to ensure that the Apache mod_rewrite module is enabled. There are dozens of tutorials on Wordpress installation in a sub folder but none specifies that. I hope this can help.

Related

Update path for Wordpress script-loader.php

I'm working on a Wordpress site that is showing some console errors. It is not finding the files for a few scripts that are being loaded from script-loader.php, which is a Wordpress core file.
The issue is that the Wordpress environment for this site contains all the Wordpress core directories and files inside a directory called WP. Since Wordpress is not considering that, it is not able to find the resources since the path is incorrect.
script-loader.php contains this line of code $scripts->add( 'editor', "/wp-admin/js/editor$suffix.js", array( 'utils', 'jquery' ), false, 1 ); if I include /wp/ before wp-admin everything works as intended, but of course, I should not modify a core file.
How can I update the path without modifying a core file so Wordpress will find these files?
Have you gone over the documentation for Having WordPress in a subdirectory? If you installed WordPress under the standard "root path" method, you may need to change your .htaccess file, note specifically the RewriteBase and second RewriteRule:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>
# END WordPress
There are plenty of other resources on running WordPress from a subdirectory, but the basics generally boil down to:
Make sure your rewrite rules accommodate the directory you're using
Make sure your siteurl and homeurl options are set properly

Wordpress redirecting to htdocs folder in xampp

I had setup wordpress on /blog directory. Everything was perfect. Today I tried to tweak 2-3 things as it was not coming up on server. I came to know about siteurl and home to be defined. But after a little while its not working now anymore. I rolled back all changes (there were only 3 changes), but still issue is not getting solved.
So while I configured wordpress it was running on http://localhost:5000/blog. For this reason, options table is also having this
1 siteurl http://localhost:5000/blog yes
2 home http://localhost:5000/blog yes
3 blogname Stockarea yes
4 blogdescription Just another WordPress site yes
But now when I am running it back on same url that is http://localhost:5000/blog it redirects me to http://localhost/blog and gives error 404 - Object not found!. I have rolled back everything to its initial state and still it is like this.
I even tried to add this in wp_config.php
define( 'WP_HOME', 'http://localhost:5000' );
define( 'WP_SITEURL', 'http://localhost:5000' )
But no luck at all. Tried restarting xampp server still no luck. Why is wordpress redirecting me to htdocs folder
Open wp-config.php file in the WordPress folder, and set following parameter.
define('WP_HOME','http://localhost:5000/blog');
define('WP_SITEURL','http://localhost:5000/blog');
Please check your .htaccess file, hope the below code solve your issue :
# 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
Open wp-config.php file in the WordPress folder, and set site
url(define('WP_SITEURL','http://localhost:5000/Stockarea/index.php');
folder name

mod_rewirte (.htaccess) strange behavior for URLs having ".profile" text

I got a hosting with WordPress engine installed and inside the root of WP engine folders I've created another web application which is having problems with URLs containing .profile word. When this text is added to URL I'm always receiving 404 error.
Here's an example:
WordPress blog URL: https://mainsite.com
Sub web application folder name: webapp
Sub web application access URL: https://mainsite.com/webapp/
So, when I try to access URL like this: https://mainsite.com/webapp/login.php?code=user.profile I'm receiving error 404. At the same time URL like this: https://mainsite.com/webapp/login.php?code=user.profilb is working fine (2nd URL got last letter replaced by another symbol).
I think this is an issue with WordPress default mod_rewrite settings, here they are:
# 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 got no clue at all why this could happen with .htaccess file like this. Could you suggest please?
It turned out that the issue was with mod_security of a2hosting. They were blocking all sensitive linux files and folders, like: .profile, .htaccess, .bashrc...
Hope, this will help someone.

Linux Apache2 Wordpress core in subdirectory but no redirect to wp-admin

My current Wordpress installation is located in /var/www/html/mydomain.tld/cms/ and my WP_SITEURL is set to https://mydomain.tld/cms and WP_HOME to https://mydomain.tld in the wp-config.php.
In /var/www/html/mydomain.tld/index.php I have require( dirname( __FILE__ ) . '/cms/wp-blog-header.php' );.
/var/www/html/mydomain.tld/.htaccess has the following code:
# 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
The /var/www/html/mydomain.tld/.htaccess is empty.
My permalink is set to "day and name": https://mydomain.tld/2018/06/02/sample-post/.
The current behavior is that I can browse using https://mydomain.tld and pages like https://mydomain.tld/about work without any problems.
The issue is that I put the wordpress installation in a subdirectory to make sure https://mydomain.tld/wp-admin will return a 404. But right now it returns a 302 pointing to https://mydomain.tld/cms/wp-admin effectively redirecting any attacker to the right place.
How can I configure my wordpress and/or Apache2 to behave the way intended?
If you have mod_alias you can
Redirect 404 /wp-admin/
As in throw 404 on that url
Taken from https://webmasters.stackexchange.com/questions/42822/how-to-redirect-specific-url-to-404-in-htaccess
I have not tried it yet.

Main Site Displaying subdirectory in URL

My Main site displays (mypage.com/site) and all following pages include /site as well
How do I achieve (mypage.com) and no subdirectory displaying?
I have tried Removing the /site in the Site Address URL in Wordpress settings.
But it broke my login and disables me from logging in.
what must I do to remove the /site subdirectory folder dislaying on my website?
What do I do in my htaccess file?
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
</IfModule>
# END WordPress
I supposed that your WordPress installation is under /site folder. If it's true, you can do it:
If you already has changed the URL, on General panel, to http://mypage.com (without /site), you just need to copy the index.php (under site/) to the root folder.
After copy the index.php file, edit it, adding site/ to the path to wp-blog-header.php:
require( dirname( __FILE__ ) . '/site/wp-blog-header.php' );
The detailed steps of this process are on "Using a pre-existing subdirectory install
" at WordPress docs: http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
Have you tried to change your document root in Apache?
Something like:
DocumentRoot /path/to/your/site
I don't know if you have access to your hosting, but this would be the best solution as far as I know.
If you can't do it for yourself, you can ask to your hosting provider to do it for you.

Categories