.htaccess execution order in subdirectories (wordpress/laravel) - wordpress

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.

Related

apache htaccess mod_rewrite to check cache folder first then run WordPress index.php

I am setting up a very simple cache for my own WordPress plugin... I have been researching this here on StackOverflow and elsewhere for a couple of days. Found some great answers that were very close (looking for image files, etc), but none for this specific scenario - and modifying other solutions is not working.
I've got everything working except the rewrite rules to do the following:
Incoming request for either http / https
domain.com/page-slug/ OR domain.com/year/month/page-slug/
Need htaccess to first check the cache folder for
domain.com/wp-content/cache/myfolder/page-slug.html
(please note the incoming request can be for "/page-slug/" OR "/page-slug" and the cache file name has the ".html" extension to make it "page-slug.html")
If the cache file does not exist, then just
...go through the usual WordPress index.php process
Also -- what if there is no slug/page name in the url?
ie: the home page ... can htaccess direct
domain.com to domain.com/wp-content/cache/myfolder/index.html
and if the cached index.html does not exist, go to the WP index.php
Is there a way to do the above cache checks purely with the .htaccess rules? Any guidance would be greatly appreciated.
( I hope my explanation above was clear -- I get confused myself! LOL )
UPDATE:
I found a good answer in htaccess rewrite if file not exists in cache folder by anubhava and tried to modify it as follows, I think it is close, but its not quite working:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# Admin area
RewriteRule ^admin(.*) admin$1 [L]
# Check if file *.* exist in the cache foldel
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/cache/ebg/$1 -f [NC]
RewriteRule ^(.+?)/?$ /cache/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
If the above solutions don't work, please contact your web host provider. Most likely you don't have Mod_Rewrite activated on your webhost package.

WordPress Permalinks not found in subfolder

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.

Problems with wordpress redirects of a site inside a site

I've been digging through all sorts of tutorials on this and messing with a bunch of multisite/htaccess stuff. Let me give you my scenario and see if someone can tell me what in the world to do to make it work.
I have a wordpress site in a folder
/mudmin6
That site is mudministry.org
I have another wordpress site (totally separate) in a subfolder of that site
/mudmin6/userspice
That site is userspice.com
Ideally I would like to be able to access this site by typing either of these two things...
mudministry.org/userspice
or
userspice.com
So far, that works. However, I can't do something that's really important.
I can't type, say
userspice.com/forums and get to my forums. I get an internal server error. The only way to get to the forums is to go all the way back to mudministry.org/userspice/forums
Can someone tell me what needs to change in my .htacces, wp-config, or wordpress dashboard to make this happen (and in what subfolder to make these changes?)
.htaccess for mudministry.org
# 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
<Files 403.shtml>
order allow,deny
allow from all
</Files>
.htaccess for userspice
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /userspice/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /userspice/index.php [L]
</IfModule>
# END WordPress
I know that there are a lot of people who will say why do I need to do this? I need to do it for a grant we have. The initial domain must be accessible by mudministry.org/userspice but it's also really annoying that I can't type userspice.com/anything and get to any of my pages.
Perhaps you can use the internal Proxy [P], I have not done this before, but let me know if this works.
You will want to put this into the root .htaccess
RewriteRule ^(userspice)/(.*)$ http://userspice.com/$2 [NC,P]
You may also want to use ProxyPassReverse to make sure any redirects are done as you expect. This may not work, depending on how you have relative and absolute urls used in your application. But if you dont mind that when the user starts to browse around in the userspice directory, that they are switched over to the userspice.com domain, this could work

wordpress htaccess issue

i have been writing .htaccess for the site http://hoteldevserver.com/~hamislan/ when i can the permalink to /%postname%/ its shows the following error when try to view the page.
The requested URL /~hamislan/info/services-amenities/ was not found on
this server. Additionally, a 404 Not Found error was encountered while
trying to use an ErrorDocument to handle the request.
i have my .htaccess file as
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
i have my wordpress file directly in www
Tthis could be one of a few things.
First check that your htaccess is readable by apache. I'm assuming it is.
Then check that you have mod-rewrite enabled in apache.
Lastly, it could be this symlink issue. And to fix this, you can add this to the top of your htaccess file or your can enable it in your vhost directive (I'm just assuming you're using a vhost) Sorry I don't have an example of how to do it in the vhost off the top of my head.
Options +FollowSymlinks
Also each time set your permalinks to the default and then switch it to the permalink style you want.
EDIT
Additionally, the url location of your website is not at the base http://hoteldevserver.com/~hamislan/
So you may need to edit your rewrite rule for base url. It's call RewriteBase
Right now RewriteBase is / you may need to change that to /~hamislan/

Problem with htaccess file. Wordpress Plugin tells me there is one, I can't find one?

i have an really unusual problem i've never had before.
i've no .htaccess file on my server. looked everywhere, there is just no file, but a Wordpress Plugin (AskApacheRewriteRules) tells me that the following Rules are active:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
any idea why that could be, i've already wrote my hosting provider, but their service isn't the best.
even if i create an htaccess file with other rules and save it to my root of the server, it doesn't change anything. The plugin always tells me the same and i believe the plugin, because i'm having issues with the /index.php/ in my url (that i don't want to have).
any ideas?
On the AskApacheRewriteRules options page, did you make sure that using_index_permalinks is set to false and that using_mod_rewrite_permalinks is set to true? If this isn't the case, WordPress will attempt to use PATH_INFO for your permalinks, resulting in /index.php/(permalink_structure).
Note that the WordPress rewrite class stores its rewrite rules as a WordPress option in the database, which is where AskApacheRewriteRules gets its information. The plugin also apparently formats the rules with the mod_rewrite_rules function before echoing them to the page, which will surround them with:
<IfModule mod_rewrite.c>
...
</IfModule>
So, the likely reason you can't find the .htaccess file is because it doesn't exist; the rules are just present in the database. The reason why the rules are present in the database is because you're using permalinks, and this is the auto-generated WordPress ruleset, which is saved regardless of whether it's actually being used or not.
Edit: You must have a .htaccess file in the root of your web directory with the following contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If mod_rewrite isn't available, we'll do this a hackish (and bad) way...
ErrorDocument 404 /index.php
</IfModule>
The rewrite_rules option is stored at SELECT option_value FROM wp_options WHERE option_name = 'rewrite_rules', but it gets regenerated every time you change the permalink, and isn't used except for writing to .htaccess from what I can tell.
Anyway, those are definitely the correct rules for what you want to do. Are you sure that mod_rewrite is enabled on your host?
Edit:
Let's make 100% sure that mod_rewrite is working correctly and go from there.
Create a .htaccess file in your web root with the following rules, exactly as written:
RewriteEngine On
RewriteRule ^rwtest http://stackoverflow.com/ [R,L]
Then go to your site with the URL example.com/rwtest and see if you get redirected to StackOverflow. If not, something is wrong with mod_rewrite. If you do, then at least we know that piece isn't the problem.
Have you checked if it's defined in your apache configuration file (it appears that the plug is showing an excerpt from that).

Resources