【问题标题】:Replace Space (%20) with dashes in url using .htacess使用 .htaccess 将空格 (%20) 替换为 url 中的破折号
【发布时间】:2013-04-22 00:43:47
【问题描述】:

我在 .htaccess 中重写 url 时遇到问题。我的 url 数据来自数据库,其中也包含一些空格。我想从我的网址中省略空格,并想用破折号替换它。

目前我的 .htacess ..

http://www.xyz.com/detail-10-Event%20Tickets.html

我希望它被替换为

http://www.xyz.com/detail-43-61-Event-Tickets.html(这就是我想要的。)

请找到 .htaccess 的代码并建议我应该进行哪些更改来解决此问题。

Options +FollowSymLinks
<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule uploadPRODUCT-(.*)-(.*)-(.*).html$ uploadPRODUCT.php?cid=$1&aid=$2&tid=$3

    RewriteRule ab-(.*)-(.*).html$ products.php?cid=$1&cname=$2 
    RewriteRule detail-(.*)-(.*)-(.*).html$ productDETAILS.php?cid=$1&aid=$2&pname=$3


    RewriteRule (.*)-(.*).html$ cms.php?name=$1&cmsid=$2



    errorDocument 404 http://www.xyz.com/notfound.php 
    errorDocument 500 http://www.xyz.com/500error.html

    RewriteCond %{http_host} ^xyz.com.com [NC]

    RewriteRule ^(.*)$ http://www.xyz.com/$1 [R=301,L] 


</IfModule>

【问题讨论】:

    标签: .htaccess url-rewriting


    【解决方案1】:

    由于您从数据库条目创建 URL,我将在创建 URL 时替换空格。您可以为此使用str_replace

    $url = str_replace(' ', '-', $db_column);
    

    【讨论】:

      猜你喜欢
      • 2013-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-08
      • 1970-01-01
      • 2011-10-22
      • 2013-12-11
      • 2013-07-08
      相关资源
      最近更新 更多