This is a strange behavior I can’t come up with a good explanation for:

If you append /?name to a WordPress URL, it is loading the blog page.

I came up with it by creating a custom Aweber “thank you” page, which is supposed to load at http://mydomain.com/thank-you. However Aweber appends a lot of information to the URL via query strings, so the URL ends up being something like:

http://mydomain.com/thank-you/?email=my%40email%2ecom&from=my%40email%2ecom&listname=name&meta_adtracking=location&meta_message=1&meta_required=email&name=&submit=Submit

This doesn’t open the thank you page but the blog. As soon as I remove the name part, it loads the correct page.

And reverse engineered: every WordPress page seems to load the blog if /?name is appended to the URL. See:

  • rollingstones.com (I’m not allowed to post 2 links)
  • rollingstones.com/?name

(Interestingly enough the rolling stone example doesn’t affect pages. /band/ stays /band/ even when going to /band/?name. In my example it also affects the page)

Any ideas where this behaviour comes from, and how to overcome it? Thanks!

2 Answers
2

Those are reserved keywords

When you visit a WordPress blog you have:

blogindexpage/?queryvariables=queryvalues

So for a search request:

example.com/?s=searchterm

For a post/page of ID 12:

example.com/?p=12

etc etc

Pretty permalinks hides all this by using regular expressions to map nice looking URLs on to their equivalents. This doesn’t prevent someone from still doing that though, e.g.

tomjn.com/?s=query_posts

Will still search my website for ‘query_posts’, even though I’ve added pretty permalinks.

The same is true of all the query variables listed under the WP_Query documentation. These variables are added to the query WordPress runs, and the template chosen and the posts loaded are dependent on those query variables

So how Do I Fix My Issue?

Don’t use reserved keywords and query variables to name your post variables. Or better yet, use POST rather than GET to submit your forms, especially where emails and submissions are concerned ( imagine if I visited that page and refreshed 20 times or had it open in my tabs and closed and reopened my browser over several days? )

Since you’ve stated you can’t change from ‘name’, I advise you instead add something similar to this to your htaccess:

RewriteCond %{QUERY_STRING} (.+?)&name=(.+)
RewriteRule ^thank-you/ /thank-you/?%1&fullname=%2 [R,NC,L]

As described here, this will rewrite the ‘name’ into a ‘fullname’ GET argument.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *