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.
Related
Our site was recently migrated from a basic php/mysql app to Wordpress. In the old app, we had content in a subdirectory which is now located on a new domain.
Examples below.
Old link:
https://example.com/vibes/vibin.php?showsomething=abcd&whatever=whatever
Should redirect to:
https://vibes.com/vibin.php?showsomething=abcd&whatever=whatever
The complicated angle is that the Old links are now a Wordpress installation. In the default .htaccess file of wordpress I see the following:
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I've poked around in the WP admin area but don't see how I'd safely edit that file.
Is there another way around this or are will our users just have to update bookmarks the old way?
htacess
You can edit the .htaccess file by hand using ftp and add the redirect that you want. Make a backup first. If you want to avoid ftp access then I don't recommend updating the .htaccess file at all because you'll need that access if you break something.
You could use a WordPress plugin to edit the .htaccess file to avoid ftp access, like "Htaccess File Editor." (Please make sure you have ftp access before you try this so you can put your backup back into place if it breaks.)
If you want to redirect all requests then I would look here https://serverfault.com/a/280067 to see how to create a redirect using .htacess that redirects to another domain and also keeps the query string. Maybe it would look something like this.
RewriteCond %{HTTP_HOST} !^vibes\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://www.vibes.com/$1 [L,R,NE,QSA]
If you want to only redirect requests to a certain URL on the old site, then I would look here https://stackoverflow.com/a/8416095/222564. Maybe it would look something like this.
RewriteBase /
RewriteRule ^vibes/(.*)$ http://www.vibes.com/$1 [L,R=301,QSA]
plugins
Since the old website is running WordPress, instead of editing .htacess you could use a plugin to redirect requests. There are various "redirect" plugins available. For example "404 Solution" has an option to redirect requests based on a regular expression to another domain and keep the query string. I maintain that plugin so I know it does that, but I don't know about the other plugins.
For example you would redirect from /vibes/(.*) to http://www.vibes.com/$1
This should be a simple problem to solve, but I'm struggling to find a solution that works.
I have recently deployed a Flask application, which is working fine except for an issue with my .htaccess file. The application is deployed in a subdirectory (which is supposed to be reachable at mysite.com/flaskapp) alongside a wordpress blog (mysite.com) that works fine with the below:
# 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 have found that if I delete the content of the .htaccess file, the flask application works well, but none of the wordpress links beyond the front page work. Conversely, with the content above intact the wordpress install works, but every URL in mysite.com/flaskapp/* gives a 'post not found' message from the WordPress site.
As a result I assume the setup I need is to somehow not have the above rewrite rules active for any url beginning with mysite.com/flaskapp, but feel free to correct me if this assumption is wrong.
What do I need to do the the .htaccess file to resolve this so that both the wordpress blog and the Flask application work?
UPDATE: There is also a .htaccess file in the flask application's directory, in case that changes or explains anything:
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/user/flaskapp"
PassengerBaseURI "/flaskapp"
PassengerPython "/home/user/virtualenv/ratings/3.6/bin/python3.6"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
Try adding a line like:
RewriteCond %{REQUEST_URI} !^/directory
after the other RewriteCond lines, replacing "directory" with "flaskapp" or the name of the directory to exclude.
The flask application's htaccess shouldn't need any altering.
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.
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.
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