Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
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! –  psteinweber Jun 19 at 14:39
    
See my updated answer –  Tom J Nowell Jun 19 at 18:18
1  
Thanks a lot for going into details about my very specific use case. Really appreciate it and learned something new! –  psteinweber Jun 20 at 12:07

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

share|improve this answer
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 at 18:10
    
Thanks for the advice Tom! –  psteinweber Jun 20 at 12:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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