.htaccess用-(“%20"改成“-")重写空格 [英] .htaccess rewrite blank spaces with - ("%20" to "-")

查看:65
本文介绍了.htaccess用-(“%20"改成“-")重写空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除指向-(破折号)的链接的

I want to remove %20 on my link to - (dash),

我的.htaccess现在就是这样,

My .htaccess is like that right now,

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ icerik.php?name=$1 [QSA,L]

例如

site.com/vision-and-mision, site.com/do-re-mi-fa-so-la-si.

site.com/vision-and-mision, site.com/do-re-mi-fa-so-la-si.

实际上我搜索了一些内容,但信息非常具体,我很困惑

Actually I searched something but the informations were very specific and I'm confused

谢谢.

推荐答案

您可以在/.htaccess文件中使用以下内容:

You can use the following in your /.htaccess file:

RewriteEngine On

# Replace whitespace with hyphens, set the environment variable,
# and restart the rewriting process. This essentially loops
# until all whitespace has been converted.

RewriteRule ^([^\s]*)\s(.*)$ $1-$2 [E=whitespace:yes,N]

# Then, once that is done, check if the whitespace variable has
# been set and, if so, redirect to the new URI. This process ensures
# that the URI is rewritten in a loop *internally* so as to avoid
# multiple browser redirects.

RewriteCond %{ENV:whitespace} yes
RewriteRule (.*) /$1 [R=302,L]

然后添加您的规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /icerik.php?name=$1 [QSA,L]

如果这对您有用,并且您想使浏览器和搜索引擎缓存重定向,请将302更改为301.

If this is working for you, and you would like to make the redirects cached by browsers and search engines, change 302 to 301.

这篇关于.htaccess用-(“%20"改成“-")重写空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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