繁体   English   中英

使用htaccess删除网址中的空格或%20

[英]Removing whitespaces or %20 in url using htaccess

嗨,大家好,我可以在这里遇到一些麻烦,以便使用htaccess删除我网址中的所有20%并用连字符替换。我设法摆脱了Acer,Liquid,S1一词之间的其他20% ,S510

这是我的网址/ localhost / gadgets / product / Acer-Liquid-S1-S510%20Mobile

如您所见,最后一部分有一个%20,我该如何删除它

这是我的htaccess

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /gadgets/

Options -Indexes

RewriteRule ^brand/([a-zA-Z]+)$ brand.php?id=$1

RewriteRule ^product/([A-Za-z0-9-]+)/?$   product.php?product_name=$1-$2 [NC,L]

RewriteRule ^(.*/|)[\s%20]+(.+)$ $1$2 [L]

RewriteRule ^(.+?)[\s%20]+(/.*|)$ $1$2 [L]

RewriteRule ^([^\s%20]*)(?:\s|%20)+(.*)$ $1-$2 [L,R]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f

RewriteRule ^(.*)$ $1.php

在此先感谢大家

尝试这个:

Options +FollowSymLinks -MultiViews -Indexes

RewriteEngine On
RewriteBase /gadgets/

RewriteRule ^([^\s%20]*)(?:\s|%20)+(.*)$ $1-$2 [N,E=Redirect:1]

RewriteCond {ENV:Redirect} ^1$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R,L]

RewriteRule ^brand/([a-zA-Z]+)$ brand.php?id=$1 [NC,L]
RewriteRule ^product/([A-Za-z0-9-]+)/?$ product.php?product_name=$1 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

第一条规则删除循环中的所有空格(使用[N] ),因此我们现在不必指定多个RewriteRules一次一个地进行操作。

下一条规则(带有{ENV:Redirect}条件)是可选的,并且用于反映客户端浏览器上连字符的使用,以便创建的所有书签都链接到URL的正确非空白版本。

暂无
暂无

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

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