Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disallow users from replacing hyphens with periods on WordPress sites

After reviewing Google Analytics and ad traffic we realized that people were able to find pages on client sites in a very odd way. Replacing the hyphens with periods.

For example...

Correct permalink: www.domain.com/this-is-a-link Incorrect: www.domain.com/this.is.a.link

Both work and send the user to the same page. But I'm not sure why. We tried various browsers and it seems to work the same in all of them. Normally, this would be helpful to the user (generally speaking) but it is skewing the analytics.

I suspect the ad campaign folks created a link with the periods which started the problem. But even with fixing that, it doesn't answer the question of why this even works or how to disallow this behavior / functionality.

Any thoughts?

like image 523
Joshua Garity Avatar asked Nov 09 '22 05:11

Joshua Garity


1 Answers

Wordpress uses mod_rewrite for permalink. And mod_rewrite uses pattern matching in your urls to distinguish what to rewrite and what not to rewrite within your .htaccess file.

The . character actually means any character in regular express pattern matching which is what mod_rewrite used to determine what to rewrite.

to illustrate this better, take your example

www.domain.com/this-is-a-link

to be the correct link that you desire but in the case of

www.domain.com/this.is.a.link

it will also match as . is being read as - since single dot means any character

you can read more about mod_rewrite to get a better understand why period is being read as dashes too.

The only way to solve this is to rewrite the default Wordpress native mod_rewrite pattern or report this as a bug to ask the core communities to list it as a bug would be more appropriate. But this seems pretty common even with large site such as eBay with url

 http://www.ebay.com/rpp/halloween-events/sweet-treats

the url with

 http://www.ebay.com/rpp/halloween-events/sweet.treats

is also valid. i believe this is a limitation in mod_rewrite so you might want to live with it.

like image 199
cylua2 Avatar answered Nov 15 '22 13:11

cylua2