简体   繁体   English

去掉 ? 从带有htaccess的URL

[英]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. 最近,我将博客从Blogger迁移到了WordPress(具有相同的域),我已经使用WordPress使用每个帖子和页面的重定向插件手动管理了重定向。

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. 现在的问题是来自Google的移动网址,因为您知道Blogger为网页的移动版本提供了某种结构,该结构在URL末尾添加了?m = 0或?m = 1,这现在在WordPress内部产生了404错误。

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 例如:旧网址: http://www.example.com/2017/01/page.html : http://www.example.com/2017/01/page.html新网址: https://example.com/page/ : https://example.com/page/我已经在WordPress中管理了上述重定向,但是现在,移动网址出现了以下问题:来自Google SERP的链接: http://www.example.com/2017/01/page.html?m=1 : http://www.example.com/2017/01/page.html?m=1 ?m=0?m=0这会在网站中产生404错误与以下http://www.example.com/2017/01/page.html不同: http://www.example.com/2017/01/page.html : 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 现在,我需要一种从所有网站链接中删除?m=1?m=0 ,以便获得与WordPress中的URL匹配的清晰URL。

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 例如:我要重定向此: http://www.example.com/2017/01/page.html?m=1 : http://www.example.com/2017/01/page.html?m=1 ?m=0?m=0到此链接: https://example.com/2017/01/page.html : https://example.com/2017/01/page.html ,它将由WP中的重定向插件管理

I think its easy for apache experts to do this :) 我认为对于Apache专家来说,这样做很容易:)

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. 我在Stackoverflow上找到了一个代码,它仅解决了?m = 1的问题,并且向其中添加了一段代码以便同时处理?m = 1和?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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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