Follow symlinks inside Wordpress directory? - wordpress

I'm working with a website built on WordPress, it's a fairly standard setup in cPanel. I've developed new features for the website in Laravel. I now need to view the Laravel public directory to an accessible web address.
I've tried symlinking the public Laravel directory to a directory inside public_html (where WordPress is).
I'm getting a WP 404 error, rather than the symlinked folder (Laravel public).
/home/user/public_html/ (WordPress DIR)
/home/user/repositories/laravel-app/public (Laravel public)
I then ran:
ln -s /home/user/repositories/laravel-app/public/ /home/user/public_html/book-online
I was hopeful that when going to domain.com/book-online it would load the Laravel app but it doesn't appear to be the case.
Update
I've managed to move a little further, I've realised the directory is definitely being resolved, I can access assets, just not index.php. For example. I can go to URL:
domain.com/book-online/css/style.css
and it will load the Laravel stylesheet
domain.com/book-online/index.php
gives me WordPress 404.
This is my .htaccess in public Laravel folder.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /index.php [L]
</IfModule>

It looks like you're missing the /repositories folder in the symlink path "ln -s /home/user/laravel-app/public/"
Also make sure your DNS entry is set up to look for the url you need : domain.com/book-online in your cpanel

Setting proper permissions fixed the issue.
I needed to set permissions on the public folder to 755 and also the index.php file to 644.
For others who may land here with a similar problem: First, you must symlink the public folder (or rename the public folder and move it to a publically accessible location) and set the permissions as above.

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

How to add .htaccess file in your local host? means what should be writte in file?

object not found & 404 error in localhost xampp? .htaccess file were missing
Your wordpress installation must be in the root folder of htdocs or in a subfolder such as blog.
For example, if you install your WP in blog folder under htdocs, you can then access your website via localhost/blog URL
EDIT:
Please try saving this code as .htaccess file and put it in the /wordpress folder where your wp-config.php and index.php are located.
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Actually, when multiple xampp is installed on your PC, that error occurs and it won't go easily unless you find the correct-one ht-docs in your local disk.
You better install xampp in your local disk C where your windows reside.

.htaccess and HTTP_HOST

We have a Wordpress multisite install with sites with each having its own domain:
fantastic-training
fantastic-thinking
perceptionprofiling
In the htdocs folder we have a sub-folder with assets we are using for one of the sites and that folder is called /Aj-Isle/ the non wordpress assets should be for the https://fantastic-training.com/ site.
However the folder is available to all 3 domains which is behaviour we don’t want. So trying to look at the file DOMAIN/Aj-Isle/south.png in all 3 domains works.
https://fantastic-training.com/Aj-Isle/south.png
https://fantastic-thinking.com/Aj-Isle/south.png
https://perceptionprofiling.com/Aj-Isle/south.png
Does anybody know how can we can use the .htaccess file in the htdocs folder to restrict it so that the Aj-Isle folder is only available when the https://fantastic-training.com/ domain is requested?
I think it has something to do with the HTTP_HOST variable?
Basically I know that in English the rules I want to create are these...
If you are inbound for /Aj-Isle/ and not requesting https://fantastic-training.com/Aj-Isle/ then redirect to the root of the target domain
If you are inbound for /limesurvey/ and not requesting https://perceceptionprofiling.com/limesurvey/ then redirect to the root of the target domain
Our .htaccess file in htdocs currently looks like this...
# BEGIN WordPress
<IfModule mod_rewrite.c>
AllowOverride All
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Thanks in advance for any help or insights that can be offered.
Steve H-B
You can check the host name with a RewriteCond
RewriteCond %{HTTP_HOST} !fantastic-training.com
RewriteRule ^Aj-Isle / [R,L]
This checks, if the requested path starts with Aj-Isle. If it doesn't, proceed with the following rule(s).
If it does start with Aj-Isle, then the requested host is checked against fantastic-training.com. If the requested host is not fantastic-training.com, redirect the client to the root folder (/).
See RewriteCond for a detailed explanation
CondPattern is usually a perl compatible regular expression, but there is additional syntax available to perform other useful tests against the Teststring:
You can prefix the pattern string with a '!' character (exclamation mark) to negate the result of the condition, no matter what kind of CondPattern is used.

URL rewriting - Remove a subfolder from the url

I don't often ask questions on SOF because I usually find the answers just searching on SOF. This time it's a tough one for me! I don't have a lot of experience with htaccess. In fact I don't have much experience, 6 months out of school now!
I am working on a personal project using Wordpress 4.9.8 and Laravel 5.7.
Wordpress will is used as the entry point and the articles part, Laravel will be used for the app part to display large amount of info from database.
I am developing locally with Xampp and MySql Workbench.
I am using a virtual host to simulate the domain name.
The project is structured like so in the root folder:
Wordpress folders and files
htaccess
Laravel folder
all folders and files from Laravel
public
htaccess
The project URL is like so:
dev.domain.com/ -->Wordpress part
dev.domain.com/plants/public --> Laravel part
I need to hide the "public" folder of the URL only and still access that directory.
So far I was able to redirect directly skipping the root folder of Laravel using htaccess.
dev.domain.com/plants to dev.domain.com/plants/public
I can't seem to put the finger on it after trying everything that I found that makes sense and not sure exactly where to put it. At the root of the project or in the public directory for this part?
Here is what I have in the root of the project:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_URI} ^/plantes [NC]
RewriteRule . plantes/public [L]
</IfModule>
What I have in the public folder:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
-- Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
-- Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
-- Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Thanks for any help or tips!
After trying some solution found on SOF and elsewhere without any success, I turned around to review the way I structured the project to see if there is other simpler way to do this without htaccess.
Here is the new structure:
Wordpress folders and files
htaccess (no particular rules here so far except the ones form WP)
MyApp
Laravel folder (containing all folders and files from Laravel except the public folder)
The content of the public folder
For this to work we need to change some references in the index.php that was in the public folder to reflect the new structure.
Index.php:
require DIR . '/Laravel/vendor/autoload.php';
$app = require_once DIR . '/Laravel/bootstrap/app.php';
That it's... It works!
www.domain.com/myapp/what-ever...
No URL with the public folder in the way.
Now I will need to work to change the name of "MyApp" so it can reflect multi languages using htaccess.
During my search I found this very helpfull: https://www.youtube.com/watch?v=ybJYyU5FPv4

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.

Resources