1

I have a blog that I recently migrated from it's original platform into a self-hosted WordPress site. The old platform appended a query string to URLs for mobile views. This doesn't have any connection in the new responsive site, so URLs with those query strings result in 404 errors.

What I need is a regex for my .htaccess that will strip off the query string ?m=1 from a URL. So, for example, "www.example.com/post/?m=1" should rewrite or redirect to "www.example.com/post/"

What I have so far is this:

RewriteCond %{QUERY_STRING}  ^m=1$ [NC]
RewriteRule ^(.*)$ $1? [R=301,L]

Which does absolutely nothing :)

Suggestions?

DavidBrown
  • 182
  • 1
  • 11
  • My issue was one of syntax. The correct solution is [here][1]. Note the importance of placement when using this solution in a WordPress site. [1]: http://stackoverflow.com/questions/14071671/remove-query-string-from-end-of-url-url-using-htaccess – DavidBrown Oct 04 '15 at 01:47

2 Answers2

1

The problem is the trailing slash in /post/?m=1

#stip trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{QUERY_STRING}  ^m=1$ [NC]
RewriteRule ^(.*)$ $1? [R=301,L]
Marcos Casagrande
  • 37,983
  • 8
  • 84
  • 98
0

My issue was one of syntax. The correct solution is here. Note the importance of placement when using this solution in a WordPress site.

Community
  • 1
  • 1
DavidBrown
  • 182
  • 1
  • 11