WordPress Permalinks not found in subfolder - wordpress

I have WordPress installed in the root folder and in a subfolder. I can access the home page for the WordPress site in the subdomain, but the permalinks does not work – error 404. I have tried to reset the permalinks, but it did not help. I can’t find any .htaccess file, so I have created one myself and placed it in the subfolder directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projects/bigsargefitness/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /projects/bigsargefitness/index.php [L]
</IfModule>
Here is a link to the subfolder WordPress site:
http://ninahortendesigns.com/projects/bigsargefitness/
I have set the database options to the above direction.
Thanks for your help.

You will need to look at a few things:
.htaccess file in the root WP site (WP1) and edit it so that WP1 doesn't catch the URLs and generate 404 errors, I'm not sure if that comment assisted, I've used this answer for a similar issue.
.htaccess file in the sub WP site (WP2) and rename it to "htaccess.old" then log into your wp2/wp-admin, go to "Settings->Permalinks" check the URL structure is as desired (it doesn't usually change) and click "Save" at the bottom of the page. This will regenerate your .htaccess file within the context of the sub-directory and you shouldn't get 404 errors when you visit sub-pages like this
Here's the code from the first link edited so that it should work with your site, although if you have additional rules, you should only insert the line under the comment.
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI} !(projects) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
If you have custom rules, only insert these lines
# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI} !(projects) [NC]
Assuming you're a designer and are uploading examples of sites you've built, you should only have to do step 2 the next time you upload a new site to the wp1/projects/ sub-directory

Cause
Error 404 occurs when the resource or path you requested cannot be reached. In this case it's likely because URL rewrite isn't working properly, hence the permalink requests were still being directed to the requested path (e.g. /projects/bigsargefitness/your-category/your-post-name) instead of the rewritten path (i.e. /projects/bigsargefitness/index.php).
The following solution assumes you use Debian/Ubuntu, otherwise the principles should remain the same.
Solution
Firstly, ensure that the rewrite engine has been installed:
sudo a2enmod rewrite
Then, ensure that the engine is allowed for the subdirectory by editing/adding the following lines in the file /etc/apache2/sites-available/your-site.conf:
<Directory /var/www/projects/bigsargefitness/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
The key here is to ensure that the line says AllowOverride All instead of AllowOverride None.
Finally, restart your server:
sudo service apache2 restart
Let me know if this helps.

Related

Only site directories are showing and not the site - I suspect I need a correct .htaccess file?

This is what I have in my root folder, and when I go to my url, this is what is showing and not my website. It is a wordpress site, only structured a little different. (roots.io/composer)
This is the root folder: www.mysite.com (I know the site works, I tested it on another web hosting server.)
Inside the folder 'public_html' is the index.php file. And if I click it I go to the site, but it looks like this: /public_html
Only site directories are showing and I suspect I need a working .htaccess file.. Anyone?
/public_html
And so I have a hunch that I need the correct .htaccess file in order to find the correct folders and files. Or am I wrong?
Some other details:
In the browser I use a 'working-url': new.mysite.com because the main url is routed to another webhost until we get the new site up and running. But the files are inside the root folder. (Not mysite.com/new)
I've set the siteurl to: https://example.com/wp
And homeurl to: https://example.com
I've tried writing a .htaccess file like this, but getting the 500 internal error message:
#This is for subdirectory
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.mysite.com$
RewriteCond %{REQUEST_URO} !public_html/
RewriteRule (.*) /public_html/$1 [L]
#This is must
# 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've tried a lot of things, but can't seem to find the connecting dots. If someone out there with a clear head and more experience that could look into this, I would highly appreciated it.
Kind regards,
Me

URL rewriting not working with WordPress

I want to change URLs in one folder (cartoon) in my site to friendly SEO URLs.
This folder (cartoon) includes a PHP script not related to WordPress.
From:
example.com/cartoon/index.php?v=TitleEpisode
To:
example.com/cartoon/TitleEpisode
I read here all related questions but I did not benefit.
I have WordPress on my main domain (example.com).
I found this code in .htaccess file:
DirectoryIndex index.html index.php index.htm parking-page.html
# 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
What do I do?
Ok, based on the edit, it seems like what you want is for WordPress not to rewrite that slug but to ignore it.
You can do this by editing your .htaccess to exclude a folder. Make sure the folder is in the root directory of your site, as in, the same folder as wp-admin, wp-content, and wp-includes.
Then, open your .htaccess and add a rewrite rule to ignore that folder:
DirectoryIndex index.html index.php index.htm parking-page.html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# Add this condition with the folder you want to ignore (cartoon in your example)
RewriteCond %{REQUEST_URI} !^/(cartoon|cartoon/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
OLD ANSWER
Well, this is fairly open-ended. For a better answer, please edit the question to include what you have already tried. Also, what do you mean by "one folder"? Is this a custom post type? Is it a category or custom taxonomy? Are there different permalinks for different types/taxonomies? Please provide more details on what you want to do.
But for the usual case, here is the documentation for pretty permalinks.
First, make sure URL Rewriting is enabled in Apache. Example in Ubuntu/Debian
sudo a2enmod rewrite
sudo service apache2 restart
Now, in wp-admin, go to Settings -> Permalinks. Set the permalink to Post Name.
Then click save changes. It will either save the new .htaccess automatically if your site has the permissions to, or it will give you the new content of .htaccess to copy and paste.
Now you should be able to view a post or page and it should show the SEO-friendly links.
How are you implementing (or intending to implement) the routing of example.com/cartoon/TitleEpisode?
If this is entirely outside of WordPress then I would expect you to have an additional .htaccess file inside the /cartoon subdirectory (since this is presumably a physical subdirectory)? This alone should be sufficient to override the WordPress mod_rewrite directives in the parent .htaccess file, since mod_rewrite directives are not inherited by default.
For instance, simply enabling the RewriteEngine in a subdirectory is sufficient to override the WP directives.
In /cartoon/.htaccess:
RewriteEngine On
Then, in order to route a URL of the form /cartoon/TitleEpisode to /cartoon/index.php?v=TitleEpisode, you would need something like:
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([^/]+) index.php?v=$1 [L]
(A bit similar to the WP directives in the parent .htaccess file.)
I would avoid editing between the # BEGIN and # END WordPress markers in the parent .htaccess file since these could be overridden by future WP updates.
You would instead implement an exception before the WP directives. For example:
RewriteRule ^cartoon - [L]
However, as mentioned above, you are probably better off creating an additional .htaccess file in the subdirectory and avoid touching the WordPress installation at all.
it's done.
i enter this after the first line in .htaccess
# BEGIN for Cartoon Folder
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?cartoon/(.+)$ /cartoon/?v=$1 [L,QSA]
# END for Cartoon Folder
thank u very much

WordPress Permalinks Doesn't Work

I'm trying to create pretty permalinks through WordPress and I keep getting 404 errors. I've scoured the internet and I can't find any solution. I've never had an issue with this before so I'm totally stumped.
The hosting is under Network Solutions. I called them and they sent me this link: http://www.networksolutions.com/support/PHP-ini-for-UNIX-Shared-Hosting-FAQ
What I've tried:
1. Adding a php.ini file to my root.
2. Adding a php.ini file to the cgi-bin folder
3. Adding the rewrite commands to my .htaccess file (which is located in the root of my website).
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /stage/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /stage/index.php [L]
</IfModule>
# END WordPress
After each of these, I've resaved the permalink settings to flush the changes.
I still keep getting a 404 error.
I had the same problem on an Ubuntu 14.04 server which is running as a staging server.
In this case the rewrite module was not enabled by default; so Pagination and "non-ugly" Permalinks were not working (as they rely on .htaccess rewrite rules to work).
You have to edit the Apache conf file (in Ubuntu 14.04: /etc/apache2/apache2.conf) and change the AllowOverride setting from None to FileInfo
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride FileInfo
Require all granted
</Directory>
You may need to enable the Rewrite module:
sudo a2enmod rewrite
and to complete you will need to restart
sudo service apache2 restart
That's been bugging me for a month or so, now, so kudos to the solution found:
https://askubuntu.com/questions/48362/how-to-enable-mod-rewrite-in-apache
Login to your server using FTP, and modify the .htaccess file which is located in the same location where folders like /wp-content/ and /wp-includes/ are located. The easiest thing you can do is to temporarily make the file writeable by changing the permissions to 666. Then repeat the original solution. Don’t forget to change the permissions back to 660. You can also manually add this code in your .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
Another solution: Put index.php at the start of your custom permalink structure, for example:
/index.php/%year%/%monthnum%/%day%/%postname%/

.htaccess execution order in subdirectories (wordpress/laravel)

Good morning Stack! My website is currently structured like this:
http://www.mywordpressite.com/
http://www.mywordpressite.com/.htaccess
http://www.mywordpressite.com/portal/
http://www.mywordpressite.com/portal/.htaccess
My understand of the universe is that if I navigate to portal, (4)'s .htaccess will parsed instead of (or with preference over) (2)'s .htaccess. In reality, I am observing that even while navigating to (3) http://www.mywordpressite.com/portal/, the .htaccess from (2) is taking over.
As you can imagine, the root directory is a wordpress site with a standard wordpress .htaccess file:
/.htaccess
<files wp-config.php>
Order deny,allow
deny from all
</files>
<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 portal is a Laravel portal, with a standard Laravel .htaccess file
/portal/.htaccess
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
What I've noticed is that if I remove (2) /.htaccess, all of a sudden, everything works with the portal, so there is certainly collision occurring. I won't post my vhost stuff here since both .htaccess's work / do what they are supposed to do -- just not at the same time:
/.htaccess redirects pretty much pipes all input where the input doesn't correspond to a file or directory into the index.php file for better parsing.
/portal/.htaccess does something similar.
What I've noticed is that with both .htaccesses, if I navigate to a route that usually would be parsed by the portal's .htaccess, such as http://www.mywordpressite.com/portal/this/is/a/route I end up getting a 404 from my wordpress site (eg it piped the url into the /index.php file of the wordpress root directory), and of course that page doesn't exist in WP.
When I remove the wp /.htaccess, of course wordpress doesn't work right anymore, but all of a sudden, the portal's .htaccess starts working fine and http://www.mywordpressite.com/portal/this/is/a/route fires the appropriate route by piping the url parameters into /portal/index.php for processing.
This seems backwards to me. Any suggestions?
I think your problem lies in the fact that you've left out a RewriteBase in the portals access file:
RewriteBase /portal/
I'm not a hypertext access genius, so I can't explain what happens when you leave it out. But I'm sure that's the solution.

How to modify .htaccess to expose file at specific location on site already hosting wordpress installation?

I agreed to host a file for an online community, but I've since changed my site around so that it's now hosting a wordpress blog. What I'd like is to not break the existing URL to this one file, so, for example, when people navigate to the URL where file is being hosted, e.g. myblog.com/path/to/file, I'd like Apache to handle the URL rather than Wordpress, so that the file on the filesystem is delivered, rather than a Wordpress "We could not find the post" page. I think that the way to do this is to modify .htaccess so that that specific URL myblog.com/path/to/file does not execute index.php. Right now, here's what my .htaccess file looks like:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Could anyone tell me how to modify .htaccess to unmanage the URL to one file, but execute index.php for all other URLs?
Any guidance would be appreciated. Thanks.
These rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
will tell mod_rewrite to skip any file or directory which actually exist. As long as you don't move this special file of yours, then mod_rewrite won't redirect the rewrite to the main index.php.
Now, if you're moving the file elsewhere, but want to preserve the old url, then you'll have to do as toscho said in his answer do a Redirect.
Redirect permanent /old/path/to/file /new/path/to/file
# BEGIN WordPress ...

Resources