wordpress permanent link htaccess issue - wordpress

My WordPress site has permanent link issues - .htaccess
In the WordPress Permanent link section,
1) When I select the post name URL (www.myworld.org/sample-post/) it's not working. Actually it's throwing the 404 error whenever linked to sub pages of the web site.
eg: www.myworld.org/aboutus/
2) When I place the custom link with %index.php% it works fine (www.myworld.org/index.php/%postname%/). However all the sub pages URL coming with index.php
eg: www.myworld.org/index.php/aboutus/
I want to get rid of the index.php in all the sub pages URL.
3) Actually my website files are placed into one separate folder on the root.
eg: /newsite/... (all WordPress files wp-content, wp-include, wp-admin etc.)
Also I've placed .htaccess file inside /newsite/ directory along with other WordPress files.
eg: /newsite/.htaccess
My .htaccess file below:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./index.php [L]
</IfModule>
Even I've .htaccess file However I've 404 page issue when change the permanent link to postname.
eg: www.myworld.org/sample-post/

Try to change URL structure from Post Name to Plain and refresh your website ... once you have done check you front end page if it shows proper URLs, After doing this, revert back your Permalinks to Post Name ... hope that will fix your issue ... your .htaccess file is looking standard one at the moment.

Related

Wordpress blogpost subdirectory

I have a blog subdirectory
public_html/blog
the site can be accessed like this
https://example.com/blog
by default, the blogposts are accessed like this
https://example.com/blog/index.php/hello-world
I want to remove the index.php and access the posts like this
https://example.com/blog/hello-world
I have this .htaccess file from where i looked into how to install a wordpress subdirectory
<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>
https://www.wpbeginner.com/wp-tutorials/how-to-install-wordpress-in-a-subdirectory-step-by-step/
However when I tried to change it via
Settings -> Permalinks -> Common Settings -> Post name
I end up with a 404 from the main wordpress installation. I have a faint idea that this might be an issue with the htaccess? But i don't really get how to fix it.
when I remove the index.php with the settings it gets redirected to the 404 of the main wordpress installation
That's because the rewriting for that main WordPress installation rewrites everything that does not match a physically existing file or folder, to its own index.php. (Which then goes and looks up the requested URL in its database, doesn't find any matching content, and responds with a 404.)
/blog/index.php/hello-world matches the existing index.php in that folder (the rest is considered PATH_INFO), so the rewriting of the main WP leaves it alone.
But /blog/hello-world does not match anything that exists in the file system.
So you need to exclude any paths starting with /blog/ from the rewriting inside your main WP installation.
https://stackoverflow.com/a/15297697/1427878 shows the basic way to do that, although there the content between the # BEGIN WordPress/ # END WordPress comments gets modified (which one should not do, because that part will be overwritten when the permalink settings get flushed in the backend.)
Better to do it outside of those. Try and put this at the very top of your .htaccess of the main WP installation:
RewriteEngine On
RewriteRule ^blog/ - [L]
For any path that starts with /blog/ (leading slash has already been removed from the relative path that RewriteRule matches against), simply do no rewriting at all, and make this the last rule to be processed at the same time.

Wordpress delivering every page as homepage

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].

Front page of WordPress in a subdirectory automatically redirecting and adding a trailing slash to front page URL?

I'm working with a WordPress installation in a subdirectory. I'd like the front page URL to not have a trailing slash. I've already set the permalinks to not have any trailing slashes in the WordPress admin screen. However since this WordPress installation is in a subdirectory, the trailing slash was still appearing on the front page. So I worked with the .htaccess files in the root directory and the WordPress installation directory to try and get rid of it on the front page as well. It doesn't seem to be working and I think WordPress might be adding the trailing slash to the front page and redirecting somewhere within the PHP itself, perhaps in the /wp-includes/canonical.php file. There are several lines in that file that specifically mention always adding a trailing slash to the front page -- yet I commented them out and the trailing slash is still showing up.
With the current setup:
all of the pages in the WordPress installation except for the front page fail to load -- the 404 page in the root directory of the hosting is shown instead
/wordpressdirectory redirects to /wordpressdirectory/ and shows the front page
/wordpressdirectory/ doesn't redirect and also shows the front page
/wordpressdirectory/index.php redirects to /wordpressdirectory/ and also shows the front page
Here is what the .htaccess file in my root directory looks like:
Options -Indexes
DirectorySlash Off
RewriteEngine On
RewriteRule ^wordpressdirectory$ /wordpressdirectory/index.php [L,R=302,E=LOOP:1]
And the .htaccess file in the WordPress installation directory is now empty -- I got rid of all of the default RewriteRules that came with WordPress for now.
But just in case, here is what the .htaccess in the WordPress installation directory used to be (all default, with no personal edits yet):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpressdirectory/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpressdirectory/index.php [L]
</IfModule>
# END WordPress

Wordpress permalinks with files and folders out site of Wordpress

I have a wordpress site and I also have pages/files/folders that I've created outsite of wordpress. Right now, I have no permalinks with my URLs as site.com?p=123. I want to have permalinks (pretty links) as site.com/postname (I know the permalink string is /%postname%/). I also have pages that are on my site that have nothing to do with the wordpress site.
When I changed the permalinks in wordpress, all my posts work fine just like they should. But when I try going to an outsite wordpress page/folder like site.com/file_name.php or site.com/folder_name/ I get HTTP 404 not found.
Is there a way that I can do this, or am I stuck with having just the post id permalink?
The default WordPress .htaccess configuration for permalinks should handle files that exist on the file system outside of WordPress. You can read about using permalinks in the Using Permalinks documentation on WordPress.
Of note is the snippet that you're supposed to include in .htaccess (so maybe update your .htaccess file to contain this content):
# 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 RewriteCond clauses tell WordPress that if the current URL either points directly to a file or to a directory, then WordPress will ignore it and let the file load normally.
Open up the Wordpress .htaccess file after enabling SEO permalinks and add the following line on top:
ErrorDocument 401 default
Let me know if that works, or you can always explicitly allow those specific files/folders in the .htaccess file.

.htaccess rewrite issue only loading homepage

I have moved a site from my test dev to a live server (its wordpress) and for some reason no matter what page I click on only the homepage loads.
Think I have narrowed it down to my 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
and this line in particular:
RewriteRule . /index.php [L]
If I remove this or remove the htaccess completly I get a Forbidden 403 error.
I was hoping someone could help me figure this out?!
Very common issue is redirect plugin. Disable all plugins and post back. Have you got your website in the root folder or is it in the sub directory?
Update:
Changing the Site URL
There are four easy methods to change the Site URL manually. Any of these methods will work and perform much the same function.
Edit wp-config.php
It is possible to set the site URL manually in the wp-config.php file.
Add these two lines to your wp-config.php, where "example.com" is the correct location of your site.
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');
This is not necessarily the best fix, it's just hardcoding the values into the site itself. You won't be able to edit them on the General settings page anymore when using this method.
Source
Update:
Goto
wp-config.php
and add
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');
Turned out there were a bunch of random files in the root, with the FTP I only had access to the public_html. There were a number of htaccess files and other config files which we cleared out and it solved the problem.

Resources