Forum Moderators: phranque

Message Too Old, No Replies

php page should not show without parameter

how to redirect? or rewrite

         

indias next no1

3:42 pm on Aug 8, 2010 (gmt 0)

10+ Year Member



Hi friends,

in my forum

i am having a page www.example.com/topic.php
on that page there will be no details, but it is the template for the parameters page

say for example :
www.example.com/topic.php?id=101
www.example.com/topic.php?id=102 .......

on each page the content will be different.

now the problem is , when i search google i find

www.example.com/topic.php
www.example.com/topic.php?adslfjalkdfjsldjf

pages with duplicate content, now for my website keyword rankings are down in google.

please let me know how can i restrict the access of topic.php page.

only www.example.com/topic.php?id=101 or 102 or 103 should be shown to public as well as google,

topic.php page should be hide . how can i do it ? please guide.

g1smd

4:22 pm on Aug 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Modify the PHP script so that when a non-valid parameter is requested, or no parameters are attached, it returns the correct HTTP 404 status header and an error message.

The basic code is something like:
IF ($GET["topic"] == '')
{HEADER ('HTTP/4.01 Not Found')};


The example tests only for "blank" value. A more robust test would be to test for "not digits".

wildbest

4:35 pm on Aug 8, 2010 (gmt 0)

10+ Year Member



only www.example.com/topic.php?id=101 or 102 or 103 should be shown to public as well as google,


One possible solution is to use canonical link tag.

<link rel="canonical" href="http://www.example.com/topic.php?id=101" /> or 102 or 103 on the corresponding page.

The other solution, like already said, is to mod_rewrite redirect request to a page where script will check the validity of every request and corresponding page served or 404 Not Found.

g1smd

5:43 pm on Aug 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The canonical tag is of no use when no topic number is contained in the URL request. Return 404 for those requests.

There is no Mod_Rewrite code in my example. This is a solution that can be wholly fixed using an extra module/function in your PHP script.

g1smd

5:44 pm on Aug 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Typo: 4.01 should say 1.1 above.

indias next no1

2:13 am on Aug 9, 2010 (gmt 0)

10+ Year Member



thanks friends,

g1smd as you said, i am trying to fix the problem using PHP

g1smd

6:09 am on Aug 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Make sure the checks are done, and error message sent, before your PHP outputs anything else to the browser, otherwise you will get the "Headers already sent" error message.

jdMorgan

3:21 pm on Aug 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On Apache 1.3.x, add this to your /.htaccess file:

# If topic.php is requested with an invalid query string, rewrite
# the request to a nonexistent filepath to force a 404 response
RewriteCond %{QUERY_STRING} !^id=[0-9]+$
RewriteRule ^topic\.php$ /a-filepath-which-does-not-exist [L]

On Apache 2.0 and later, you can use:

# If topic.php is requested with an invalid query string, force a 404 response
RewriteCond %{QUERY_STRING} !^id=[0-9]+$
RewriteRule ^topic\.php$ - [R=404,L]

I assumed that you've already go other working rewriterules in your .htaccess file. If not, you will need to add both of the following lines or only the second of these lines ahead of the code above. Only testing will reveal whether you need and/or can use both lines.

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine on

Jim