简体   繁体   English

使用重写规则.htaccess替换URL中的特殊字符

[英]Replace special characters in URL using rewrite rule .htaccess

I am rewriting my url by using 我正在通过重写我的网址

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{QUERY_STRING} ^search_query=(.+)$ 
RewriteRule ^search/videos$ /search/videos/%1? [R=301,L]

from XXX.XXX.XXX.XX/search/videos?search_query=XXXX+XXXX to XXX.XXX.XXX.XX/search/videos/XXXX+XXXX XXX.XXX.XXX.XX/search/videos?search_query=XXXX+XXXXXXX.XXX.XXX.XX/search/videos/XXXX+XXXX

now the problem is i want to replace "+" with "-" space (+) with hyphen. 现在的问题是我想用连字符将“ +”替换为“-”空格(+)。 I have tried below code but not work. 我已经尝试了下面的代码,但没有用。

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)(?:\+|%20|\s)+(.+?)\sHTTP [NC]
RewriteRule ^ %1-%2 [L,NE,R=302]

I have above code to replace space with hyphen, but i want to integrate with below code. 我上面的代码用连字符替换空间,但是我想与下面的代码集成。

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{QUERY_STRING} ^search_query=(.+)$ 
RewriteRule ^search/videos$ /search/videos/%1? [R=301,L]

i have fount the solution on above query i have write rewrite rule like this. 我有上述查询的解决方案,我有这样写重写规则。

first convert you URL what you want to then you remove the special characters form URL. 首先将您想要的URL转换为所需的URL,然后从URL中删除特殊字符。

RewriteCond %{QUERY_STRING} ^search_query=(.+)$ 
RewriteRule ^search/videos$ /search/videos/%1? [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)(?:\+|%20|\s)+(.+?)\sHTTP [NC]
RewriteRule ^ /%1-%2 [L,NE,R=302]

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

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