htaccess的重定向所有的URL使用%20 - [英] .htaccess redirect all urls using %20 to -

查看:322
本文介绍了htaccess的重定向所有的URL使用%20 - 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有重复URL的问题,如:

I had a problem with duplicated urls, like:

/term/this-is-the-term
/term/this%20is%20the%20term

至极我已经解决了通过确保所有环节使用 - 相反,

现在我想重定向任何索引网址与 20%所以从谷歌网站管理员的问题自败(实际上是解决)

Now I want to redirect any indexed url with %20 so the problem dissapears from google webmasters (and is actually solved)

我如何使用重定向任何URL 20% -

How can I redirect any url using %20 to - ?

我知道简单的重定向的基础知识,但我闻到这只能通过使用正则表达式来实现,至极我不是那么熟悉,

I know basics of simple redirections but I smell this can only be achieved using a regex, wich I am not so familiar with,

任何线索?

推荐答案

尝试:

RewriteEngine On
RewriteRule ^(.*)\ (.*)$ /$1-$2 [L,R=301]

这与重定向的空间(20%),使用破折号,而不是任何东西。你需要把该规则的的你在htaccess的文件中的任何其他规则在你的文档根目录(或你想这一切的目录申请)。

That redirects anything with a space (%20) to use a dash instead. You'll need to put that rule before any other rules you have in the htaccess file in your document root (or in whatever directory you want this to apply to).

要拥有这是否适用于您的查询字符串(之后的所有 ?)你需要做一些特别的东西:

To have this apply to your query string (everything after the ?) you need to do something special:

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

这篇关于htaccess的重定向所有的URL使用%20 - 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆