: Wordpress Multisite- How to restrict a non-wordpress page only to one domain I am running three blogs from a wordpress multisite. Currently, I am developing a separate, non wordpress application.
I am running three blogs from a wordpress multisite. Currently, I am developing a separate, non wordpress application. I want to link this application with blog1. I put the application in the subfoler of my root directory (The Wordpress multisite is installed in the root). I linked the application in the menu of blog1. So far so good.
But, it is possible to access the application from all the three blogs. I want the application to be accessible only from blog1-domain/my-app/ but when I tried blog2-domain/my-app, it just opened normally. Generally, the application is accessible from all the three domains followed by /my-app.
I don't think it is proper to go this way. Then, what can I do to restrict my app to be accessible only from a my blog1-domain/my-app ? Or am I not using a good blog structure?. I am open to all kind of suggestions.
Thank you for your help.
More posts by @Shanna517
3 Comments
Sorted by latest first Latest Oldest Best
You can use your .htaccess to only allow access from the domain you want.
RewriteCond %{HTTP_HOST} !^www.yourblog.com [NC]
RewriteRule ^directoryname/ - [F]
First line checks if the incoming host header doesn't match your allowed host. If it doesn't then the second line will catch the request.
The second line forbids requests to your app's directory.
if you want to discourage search engine to crawl your app
use robots.txt
block your app folder
User-agent: *
Disallow: /my-app/
WordPress multisite uses wild card sub-domains. The problem is your application isn't integrated with WorPress. So anyone accessing the ~/my-app/ folder will see it's contents, and WordPress isn't going to stop them simply because it's a sub-folder in your WordPress installation. Restricting access to only blog1 you'll need to
Your application should use require('wp-blog-header.php'); in it's header. This will allow you to use WordPress functions within the application. You can then write a conditional in the header to restrict access to only blog1. This isn't tested so i'm not 100% sure if it would work. When the page blog1-domain/my-app/ loads it might recognize that as part of blog1. If someone goes to blog2-domain/my-app/ it might recognize it as blog2 and restrict access. You can test the code below or simply try echoing the blog ID in your app, and access it from different blogs to see if it's picking up each blog ID. If so you can restrict access with the code below.
<?php
global $blog_id;
if ($blog_id == 1) {
code here;
}
elseif ($blog_id == 2) {
and here;
}
else {
and default here;
}
?>
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.