3

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:

(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

4

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.

3
  • Thanks for illuminating me (us) on this! Didn't know about that. Unfortunately "not using reserved" keywords isn't a solution in that case, as it's outside my control what Aweber appends to the query strings. At least from what I know so far... Thanks again! Jun 19, 2014 at 14:39
  • See my updated answer
    – Tom J Nowell
    Jun 19, 2014 at 18:18
  • 1
    Thanks a lot for going into details about my very specific use case. Really appreciate it and learned something new! Jun 20, 2014 at 12:07
-3

In my research inspired by Tom J Nowell's answer I found out that the following line in wp-config.phpsolves the problem

unset($_GET['name']);

Found here

1
  • 2
    this will cause compatibility issues and will break certain rewrite rules. It will also break the thankyou script your originally had the issue with as 'name' is now unusable. I strongly advise against this
    – Tom J Nowell
    Jun 19, 2014 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.