Wordpress delivering every page as homepage - wordpress

I have a wordpress install on a host and a DNS pointing to that host. The issue is that the site is being migrated from a subdirectory and that structure needs to remain intact.
So www.webpage.com/subdirectory/ now points to www.wordpress-host.com where the content is hosted.
Inside Wordpress the site URL is set to www.webpage.com/subdirectory/ and the .htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdirectory/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdirectory/index.php [L]
</IfModule>
With this setup the homepage renders normal, all css and javascript load correctly.
The issue is that no matter what page/post is viewed it is always renders the homepage.
I have also create a plugin to replace all host URLs with the site URL, but when this is active every file is the homepage, so is you inspect any .css or .js file it is the HTML from the homepage.
Is there something im missing in the htaccess or another solution to get this working?
I think that the htaccess is incorrect, but im not sure how to have it work with a fake subdirectory.
-The new host is just a wordpress host, so the original site will remain on its host, but the wordpress install is being moved.

If you want to redirect from /subdirectory to /, then first of all, the .htacess should be at /subdirectory because that will be where all the url requests coming from.
Secondly on .htaccess setting, the RewriteRule then should be RewriteRule . /index.php [L].

Related

Why is my page displaying in the browser but showing a 404 server response? Is it the htaccess?

I have built a specific landing page for a site here :
https://www.sunfimmo.com/programmes-immobilier-neuf-la-reunion/le-grand-bleu/
/le-grand-bleu/ is a directory and the filename is just index.php.
When you access the URL in a browser it displays fine but in Screaming Frog Crawler, Search Console, Lighthouse, etc, it returns a 404 server error.
The main site is a Wordpress site and this page is a standalone basic HTML PHP page that doesn't go through the Wordpress system.
So, I was wondering if the htaccess for Wordpress (see code below) is picking up the url and because it looks like a Wordpress url it triggers the Wordpress rewrite system but can't find that URL and returns the 404.
But ... if that is so, surely the url https://www.sunfimmo.com/programmes-immobilier-neuf-la-reunion/le-grand-bleu/index.php would not trigger the rewrite??
Here's the standard WP htaccess code currently being used
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
As far as I can tell, that htaccess shouldn't trigger the Wordpress rewrite because the directory exists in the first URL I posted and the filename (index.php) exists in the second url.
Has anyone got any ideas what is causing this 404?
Thanks :)

Images are not working after redirecting to root/ wordpress

I have problem with images on my website. I have installed wordpress in blog directory, co I could access my website like mysite.com/blog. I have followed tutorial on this page Giving_WordPress_Its_Own_Directory (Using a pre-existing subdirectory install), to redirect it, so I have changed site address url in settings to mysite.com, add index.php to root and add /blog/wp-blog-header.php in this fileā€¦ I also have to update permalinks and htaccess copy to root, with 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
Now my website is working fine but images are not working. I can see them but after click on them it shows 404 error page. There is /blog/ in image url. If I remove blog from url manually, it shows page with image (lightbox is not working) Could somebody help me how to solve this? thanks
I'd try Better Search Replace plugin to change urls of images in database.

Setting .htaccess for Wordpress in a subdirectory with 'Post name' permalinks

I am trying to set up a Wordpress installation, where Wordpress is in a subdirectory, but where the subdirectory is always rewritten out of the URL.
I've been trying to follow a whole bunch of other questions / posts about doing this, but no one else's solutions seem to work for me, and a lot of the time they just get the pages to load, without removing the subdirectory from the URL, which is crucial for me.
I'm also hoping for a solution that will work the same locally (http://localhost/wordpress) as it will on a live server (http://example-site.com). However, I'll explain the problem from a local point of view:
My root folder is structured like this:
.htaccess
wp /* contains all wordpress core files */
wp-content /* custom wp-content folder, which is set to be pointed at in my wp-config */
wp-config.php
So, if we ignore the .htaccess, the site would be accessed by going to http://localhost/wordpress/wp, and the goal is to access it by just going to http://localhost/wordpress.
This was achieved using this .htaccess:
RedirectMatch 302 /wp/$ /wordpress/$1
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ wp/$1
RewriteRule ^(/)?$ wp/index.php [L]
</IfModule>
However, at this point, my wordpress installation was set to use default permalinks, which create pages like http://localhost/wordpress?p=12. I need to set this to a different permalink type, which uses URL segments rather than query parameters, like http://localhost/wordpress/hello-world. Once that setting is changed, I can no longer access other pages with that .htaccess (the home page still works fine though)
I tried using this .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/wp/$1 [L]
</IfModule>
Which now causes the sub pages to load, though the home page no longer does, nor do some asset files, like http://localhost/wordpress/wp-includes/css/admin-bar.min.css
I can't seem to find a solution that makes everything work at the same time!
I'd also like to mention that I have a very small understanding of writing .htaccess files, so if anyone is going to answer this, please explain things like I am an idiot, as I may not understand you otherwise.
I am considering that you have redirected the domain to the relavant folder, or on shared hosting you have setup the domain to point to your subfolder. I am also considering that you are adding the htaccess to the root. Here is code from the official codex for your situation.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?YourDomain.com$
RewriteRule ^(/)?$ blog [L]
Replace yourdomain.com and blog with website address and directory. Delete everything else from the file. Then goto settings > permalink and change the permalink to what ever you want.

Wordpress blank wp-admin and some pages are not working with www

I have moved an Wordpress from one server to another. The address remained the same, so nothing is changed in the URL structure. The steps followed are as described in Codex page.
However when I try to access the admin page (www.mydomain.com/wp-admin) I get a blank page. Also, the same happens to some pages on my site - but not all of them. Some are working some are not.
In my .htaccess I have the usual:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Under wp-admin folder, .htaccess file is empty.
After a lot of testing, I find out that when I access http://mydomain.com/wp-admin (without www) is loading the login page, but after entering the username and password I get another blank page (it basically redirects to www.mydomain.com).
I believe this is not a .htaccess, but something inside Wordpress. I have the correct URL and HOME setup in wp_config (also because the domain did not changed after moving to a different server).
Strange thing is that some pages are working, some don't. What could be the reason?
I found that the reason for this is a blank space left on wp-config.php file, which made WP crash (not sure why other pages were working though...).

Deploying wordpress to temporary url on live server with subfolder

I have a wordpress site that I was working on locally and on a production server. The site is preparing to launch and I have to show the client that it works on the live server before the domain is transferred over. Unfortunately, the temporary url given to me is http://[ip address]/~foldername, so the site isn't working properly because it is looking in the wrong places. The homepage works fine after I put in the site_url and home_url in the admin, but clicking to interior pages is not.
How can I get it working with this temporary url but also still have it work when the domain switches over. I imagine this can be done with htaccess but not sure exactly what to do.
All I had to do was put in the subfolder in the htaccess file.. so it looked like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~subfolder
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~subfolder/index.php [L]
</IfModule>
# END WordPress

Resources