Limit web folder access to specific URL - wordpress

I am hosting two different websites using one hosting package.
My initial website is self-built and runs from the public_html directory of my host let's call this 'http://www.website1.co.uk'
I also have a Word Press blog running in a folder under the public_html - so '/folder_2', let's call this 'http://www.website2.co.uk' - this URL currently points to '/folder_2' and will load the blog when entered in to a browser.
At the moment the blog is also accessible by entering 'http://www.website1.co.uk/folder_2/'.
I would like to be able to limit access to 'folder_2' to just 'website2.co.uk' - preventing somebody typing in the 'website1.co.uk/folder_2' path and being able to view the blog.
What's the best way to achieve this, bearing in mind the folder in question is running a Word Press blog.

Try adding this in your .htaccess file in folder_2
RewriteEngine On
RewriteCond %{http_host} !website2.co.uk
RewriteRule .* http://website2.co.uk
that would redirect anyone who goes to website1.co.uk/folder_2 to website2.co.uk, but if you just want them hit a 404 put this in .htaccess instead
RewriteEngine On
RewriteCond %{http_host} !website2.co.uk
RewriteRule .* - [R=404,L]

1# move folder_2 out of public_html(you really should do that).
2# rewrite all request of 'http://www.website1.co.uk/folder_2/' to 404 in htaccess
Check below link:
Redirection Subfolder Htaccess

Related

After WordPress migration only home page loads everything else returns a 404

Getting started with a droplet on Digital Ocean, so far it's been a fun process. Now I want to begin migrating my site, so I set everything up and created an index.php to where to my root dir as a "construction" page for now. I'm setting up WordPress in a sub-dir and moved all of the contents via all-in-one WP Migration which has always worked perfectly for me.
I've given every dir and file inside of root/public_html (WordPress installation) rwx and atm ownership has been changed to www-data. So I got to loadup my site which atm would be something like <ip address>/public_html and I log in and I am propmted with the wp-admin screen. Everything is working, media files are uploaded, theme is there etc.
When I go to my home page, all the images load but I immediately notice the admin bar at the top, the wp-glyphs aren't loading and I'm getting those weird squares when your computer/phone doesn't know what it's trying to look at. Also any front-end page other than my home returns a 404. My homepage again is accessed by <ip address>/public_html so you would think my about page would be <ip address>/public_html/about, which is where WordPress is sending me to when clicked, but I receive a 404.
I've spent probably 4-5 hours now trying to figure this out and eventually turned to a guide that walks you through it but nada so far.
Can anyone offer a suggestion?
EDIT
I'd like to add that I followed WordPress's instructions on modifying the .htaccess file. I'm assuming it goes in the subdirectory correct?
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /public_html/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /public_html/index.php [L]
</IfModule>
Just as a reference for myself and anyone who might stumble upon this.
Solution
The answer was that apache was not configured correctly to read .htaccess files. If you are experiencing the same problems and have set up your own VPS, go to apache.conf, etc/apache2/apache.conf and find the correct <Directory></Directory> directive that corresponds with your website directory. Inside you should see an option that reads AllowOverride None. Change this to AllowOverride All.
If this is not the solution for you, at least it's another step out of the way.
Are you able to access wp-admin
If yes then go to dashboard->setting->permalinks
and update the permalink and the problem solved
Access your dashboard by logging in wp-admin then access settings then permanent links, Change them to any of the provided styles save the change it again to your preferred one. This will work well.

Wordpress page not taking precedence over server directory

On my wordpress site, I have a page mysite.com/download. On the same server I have a directory named download, where I store files which I need to provide on download page. So the problem is that when someone tries to access mysite.com/download, he's taken to the directory instead of the page. I have turned off the directory access for now, so it currently displays no permission to access. I want wordpress to display the page instead of the directory. I am not sure if it's a problem with the server or wordpress. I hope someone can clarify.
Try to put a redirection rule to your download.php file like this using .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/download.php$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule .* /download.php [L,R=302]

How to force Wordpress in subdirectory to use correct url after domain change

I have two Wordpress sites, one living in the root directory of my server, one living in a directory. Let's call them:
www.domain.com and www.domain.com/folder/
This worked fine until now, when I needed to change my domain and server. I moved my files from one server to the other, got everything running with the new domain on the new server, and then "parked" the old domain on the new server via cPanel, setting up the following .htaccess code in the root directory to handle traffic to the old domain:
RewriteCond %{HTTP_HOST} ^domain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301,NC]
This appears to work perfectly for the "main" wordpress install, BUT, while visiting URLs for the Wordpress site in the subdirectory produce the correct results, they display the OLD url:
So, for example, if I visit:
http://www.domain.com/folder/page/
I see the content for:
http://www.newdomain.com/folder/page/ (eg. all the links etc. are correct)
But the URL still displays as http://www.domain.com/folder/page/
Nothing I do with .htaccess, etc. seems to change this. How can I force http://www.domain.com/folder/page/ to fully redirect to http://www.newdomain.com/folder/page/ not just show the content for it?

WordPress in base.example.com and accessible from example.com give me path issue in Hostgator

I have a WordPress installation at Subdomain. I wish to have the website display the site at example.com
The WordPress folder is located at base.example.com and the path is public_html/folder1/base.
If I run the site from the subdomain with home and site url pointing to base.example.com everything works fine. If I change the second url to my root example.com copying index.php (changing the path) and .htaccess to public_html/ I get the following issue:
.htacces is not writable from wordpress
tons of redirect issue
admin bar disappear (solved here Admin bar doesn't appear on the front-end of a WordPress website)
if I open the customizer I get errors (TEMPLATE ISSUE... with default wp themes everything works)
Using USERPRO Plugin to manage my user after login I'm redirect to the default wordpress login page (that means there is something missed up in url redirect) EDIT: This is the path on the login page that appear after userpro login: http://base.exaple.com/wp-login.php?redirect_to=http%3A%2F%2Fbase.example.com%2Fwp-admin%2F&reauth=1 ... I'm still waiting for an answer from the author
sometimes when I press logout it just reload the admin page.
when I visit base.example.com I'm not redirect to example.com... is this right? it shouldn't redirect me instead?
Are 5 days that I'm trying to solve it so I also wrote to hostgator support because I think I did everything in the right way but they just say they can't support issue wich came from customization....but this is not a customization, is just making work a simple wordpress installation from a subdomain!!!
Hope you can help me!
EDIT
.htaccess (both in public_html/ and in public_html/folder1/base are the same)
# 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
index.php (in root)
require('./folder1/base/wp-blog-header.php');
index.php (in public_html/folder1/base)
require('./wp-blog-header.php');
EDIT 2
I just get some 404 errors...
Updated question 4,5,6
Your suggestion doesn't work. 301 redirect force wordpress to find his files in public_html instead the installation folder and obviously it can't find anything giving me an error. I've also changed the url form example.com to base.example.com but nothing!
I've tried to install wordpress in a simple subfolder and all the issue disappear but as I'm stubborn I want to achieve to make wordpress working in a subdomain instead a subfolder...
.htaccess being writable is not unusual, being that the site is in a
different directory.
Tons of redirect issues isn't a question, I would need an error to help you solve that problem.
Solved by my answer at Admin bar doesn't appear on the front-end of a WordPress website.
This isn't a question, I would need an error to help you solve that problem.
You should contact the UserPro support team via their CodeCanyon account for support with their product.
What error occurs when you are unable to logout? I would need an error to help you solve that problem.
This is normal behavior. You can change this through a 301 redirect in your .htaccess within the root of the subdomain folder (not the root of your website). This code excludes /wp-content/* (for uploads access, plugins access, theme file access, etc.), /wp-admin/* (for admin access), and /wp-includes/* (for important WordPress includes access). Try this code and see what happens:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/wp-content/
RewriteCond %{REQUEST_URI} !^/wp-admin/
RewriteCond %{REQUEST_URI} !^/wp-includes/
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Running Wordpress in a subdirectory (not the root)

I have a wordpress site that is currently running in a subdirectory of my website, basically put my structure is as follows:
root/wp
I'd like to keep the wordpress wp folder in the same place however have it load the wordpress site directly from the root url.
For instance currently the site loads when I go to www.mysite.com/wp however I'd like to have the wordpress site load when I simply go to www.mysite.com - currently if I go to www.mysite.com it simply loads an 500 Internal Server Error message.
I would expect I'd need to make some changes to the htaccess files - can anyone suggest how this would be done
So in a nutshell
When I go to www.mysite.com - it looks at the /wp folder but still appears as www.mysite.com in the address bar.
Adding these lines to .htaccess should do the job (not tested, sorry, it may not be sufficient):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^(/)?$ wp [L]
Update: You might wish to check https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory for a way to accomplish this that's closer to WordPress standards.

Resources