Not sure if I am posting this in the correct category… my apologies if this isn’t the right place.
I am trying to work out how to “hide” or “redirect” all .php pages so that only the homepage (index.php) is publicly visible…
Not sure if I am posting this in the correct category… my apologies if this isn’t the right place.
I am trying to work out how to “hide” or “redirect” all .php pages so that only the homepage (index.php) is publicly visible…
Can you clarify what you mean by “publicly visible”? Do you mean only that page should appear in search results, or do you mean that only your home page should be accessible to the public?
If the latter, then password-protecting the rest of the site might be the easiest and most reliable way to go.
Probably the latter… though I’m not sure how to password protect the rest of the site? Out of curiosity how would I implement option 1?
That would be the solution if the other pages were still to be accessible to the non-puplic, like admins for example.
Can you clarify further exactly what you want?
You can add the robots meta tag to those pages you don’t want indexed.
<meta name="robots" content="noindex, nofollow">
Note that that doesn’t prevent crawling; it only advises. Reputable search engines will respect the directive, but other bots may not. https://developers.google.com/search/reference/robots_meta_tag
The easiest way to password-protect the rest of the site would probably be to put it all in a directory and password-protect that. You can do that through cPanel, if you’re using it. I’m sure there will be other ways, but that’s the only one I’ve ever used.
I would use .htacces but can not post any code as I am unable to test anything at the moment. A web search will probably produce the result you need. Something like: htaccess redirect all pages to root
But would that not redirect them for everyone? Presumably they should be accessible to some, or it would be easier just to remove them.
In the original post the OP does not say some people should have access and not others.
Maybe the OP wants to modify the other pages and make them viewable later. Who can tell without more input?
To further clarify, the website I am working on is no longer required and instead a holding page has been posted until such time as the client wishes to re-instate their website. So rather than removing the original site I thought it would be better to redirect all traffic direct to the holding page.
In answer to some of your points, I don’t need to have the site accessible to some and the website does not have a cpanel.
Without knowing the .htaccess contents it is difficult to supply a solution.
If site is Apache driven and uses PHP and .htaccess redirects all traffic to index.php (common for WordPress sites or Pretty_Urls)
I would create the holdingpage.php and add the following lines to:
<?php
// add the following two lines
require 'holdingpage.php';
exit;
// all the old stuff remains and is never called
After googling your suggestion I came across a solution which I tried:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/index.php$
RewriteCond %{REMOTE_HOST} !^27.121.66.181
RewriteRule $ /index.php [R=302,L]
It redirected as I wanted, however the index.php page failed to load the relevant stylesheets and images. Any suggestions on how to overcome this?
The problem may be that you are redirecting every request which is not index.php
, this includes images and style sheets.
So you need another condition with a wildcard for just .php
files. Assuming all pages are php files, you may need to include html or htm.
Ok thanks. Could you please help me with how that code would look?
Try this .htaccess file:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.