• Resolved chillmen

    (@chillmen)


    Hi,

    When we choose a static home page, and permalink are set to %postname%
    We can access all posts of a website (of all categories) by adding this: /?page_id=0 to website url ?

    example: https://www.website.com/?page_id=0

    will display all website posts
    checked this behavior on many random blogs and i got the same result.

    Why and is there a way to block it on home page and return 404 error for example ?

    Thanks

    • This topic was modified 4 years, 5 months ago by chillmen.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator bcworkz

    (@bcworkz)

    I think that’s how WP references the blog listing page when there are no “pretty” permalinks. You could use the “pre_get_posts” action to watch for that query var and when encountered alter the query to return 404 instead.

    It might be better to prevent such a request from happening in the first place. Where’s it coming from? It shouldn’t exist anywhere if permalinks are set to %postname%.

    Thread Starter chillmen

    (@chillmen)

    Hi,

    There is a huge number of blogs that have the same problem, do a test choose random blogs that have a page as front page, and you will see.

    And yes i have /%postname%/ as permalink

    I could redirect to homepage if “/page/” and if “?page_id=0” in url

    But still don’t know why it’s happening and why its happening to many other blogs ?

    Thanks

    Moderator bcworkz

    (@bcworkz)

    /page/ and page_id=0 are two rather different things. You want /page/ but not page_id=0. On the site’s I manage, page_id=0 works on request, but it does not appear as a link anywhere, so it’s not indexed by search bots and no one normally ever requests it. It’s moot whether it 404s or not if it’s not used.

    Where is it appearing as a link on your site? I suspect it’s due to a theme or plugin. To start with, is it a link output from a template or does it appear within post content?

    Thread Starter chillmen

    (@chillmen)

    In my case i discovered the existence of it from GWT, reporting a breadcrumb error, i started searching the web about “page_id=0” and found nothing.
    By the way i created a new blog, add some posts to multiple categories, and as soon as i’ve add the “page_id=0”, i could get the list of all posts. (did not use any plugin, fresh wp install)

    here is some examples: (they use static page as a homepage) when you add /?page_id=0 to the URl you have a list of all posts on this blog with pagination.

    mhthemes____com/
    wptheme____fr
    colorlib____com
    wpmarmite____com

    Moderator bcworkz

    (@bcworkz)

    Yes, it’s intentional that such a query string works on all sites. My question is where is Google tools finding such links when “pretty” permalinks are enabled? It wouldn’t flag it unless it is found somewhere. Are the breadcrumb links part of your theme? It sounds like it’s in the breadcrumb links somewhere. You may need to check the mobile device emulator of your computer’s browser to find the links. Sometimes mobile output is different than desktop.

    I’ve also had Google tools flag an issue with breadcrumb links (but related to unsupported schema, not query strings). If the theme author will not address the issue, you have limited options. Don’t use breadcrumbs, use a different theme, or fix the issue yourself.

    Thread Starter chillmen

    (@chillmen)

    i’ve add a redirect when “page_id=0” is directly after domain name that solved the problem, of breadcrumbs.

    Thank you a lot bcworkz for your precious time

    Chillmen: How did you add a redirect when “page_id=0” is directly after domain name????
    Thanks for your help…

    Thread Starter chillmen

    (@chillmen)

    hi,
    I used the plugin Redirection,

    Add a regex redirection (from dropdown button on the right)

    Source: ^/\?page_id=0$
    Target: /

    This works for homepage only

    Thanks Chillmen.
    I tried adding a 301 redirection in .htaccess file without success.
    With the plugin Redirection and the parameters you gave me I have resolved the problem

    Thanks.

    I found a solution without plugins:
    Add in .htacces file:

    # redirection /?page_id=0 to Home
    RewriteCond %{QUERY_STRING} ^page_id=0+$
    RewriteRule ^$ / [QSD,R=301,L]
    # redirection end

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Home page and page_id=0’ is closed to new replies.