简体   繁体   中英

Remove ? from URL with htaccess

Recently I migrated my blog from Blogger to WordPress (with the same domain), I've managed redirects manually withing WordPress using the redirection plugin for each post and page.

The problem now is with mobile URLs from Google, as you know Blogger gas certain structure for mobile version of pages which adds ?m=0 or ?m=1 to the end of URL, and this gives 404 error inside WordPress now.

For example: the old URL: http://www.example.com/2017/01/page.html The new URL: https://example.com/page/ I've managed the above redirection within WordPress, but the problem now is with mobile URLs as follows: Link from Google SERPs: http://www.example.com/2017/01/page.html?m=1 or ?m=0 this gives a 404 error in the site as it is different from: http://www.example.com/2017/01/page.html

Now I need a way to remove the ?m=1 and ?m=0 from all my site links in order to have a clear URL that match the URL in WordPress

for example: I want to redirect this: http://www.example.com/2017/01/page.html?m=1 or ?m=0 TO this link: https://example.com/2017/01/page.html which will be managed by redirection plugin in WP

I think its easy for apache experts to do this :)

Thanks in Advance!

I've found a code on Stackoverflow and it solved the problem for ?m=1 only, and I've added a piece of code to it in order to handle both ?m=1 and ?m=0.

Here's the original code :

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

and here's the code after editing it:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM