如何使用htaccess在URL中将“+”更改为“ - ”

问题描述 投票:0回答:1

我想通过使用htaccess在php应用程序的URL中将“+”更改为“ - ”

示例http://hddir.com/videos/kodak+blackhttp://hddir.com/videos/kodak-black

我的htaccess代码

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]
RewriteRule ^videos/(.+)/(.+)/(.+)/(.+) search.php?q=$1&order=$2&type=$3&ptk=$4
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /search(?:\.php)?\?q=([^\s&]+) [NC]
RewriteRule ^ videos/%1? [R=302,L]
# internal forward from pretty URL to actual one         
RewriteRule ^videos/(.+)$ search.php?q=$1 [L,QSA,NC]
RewriteRule ^video/(.+).html$ watch.php?v=$1
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]
#######Options -Indexes
ErrorDocument 404 /index.php
.htaccess preg-replace
1个回答
0
投票

以下应该通过将每个域中的加号永久地重定向到同一个域但是减去而不是加号来实现这一目的:

RewriteEngine On
RewriteRule ^(.*)\+(.*)$ /$1-$2 [L,R=301]
© www.soinside.com 2019 - 2024. All rights reserved.