【问题标题】:How to change "+" to "-" in URL using htaccess如何使用 htaccess 将 URL 中的“+”更改为“-”
【发布时间】:2018-03-04 17:44:00
【问题描述】:

我想在 php 应用程序中使用 htaccess 将 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】:

    下面应该通过将每个带有加号的域永久重定向到同一个域但一个减号而不是加号来解决问题:

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

    【讨论】:

    • 改成这个 RewriteRule ^(.*)\+(.*)$ /$1-$2 [L,R=301]
    • 相应地改变了它。忘记转义“+”,抱歉。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-17
    相关资源
    最近更新 更多