PHP seo freindly url - 我想在我的php网址中删除% - ' - '

时间:2017-11-21 10:09:24

标签: .htaccess

我需要帮助从我的网址中删除%20。 我当前的网址为http://www.searchbankifsccode.com/STATE%20BANK%20OF%20INDIA

我想要的网址是http://www.searchbankifsccode.com/STATE-BANK-OF-INDIA

我的索引页面代码如下所示。

  <?php
    function create_slug($string){
    $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
    return $slug;
    }?>

<div id="list"> 
                        <ul>
                            <?php
                            $query = "SELECT DISTINCT `bank` FROM `banks` ORDER BY bank asc";
                            $res = mysqli_query($checkcon, $query);
                            while ($row = mysqli_fetch_array($res)) {
                                ?>
                                <li>
                                     <a href="http://www.searchbankifsccode.com/<?php echo $row["bank"]; ?>"><?php echo $row["bank"]; ?></a>
                                </li>

                                <?php
                            }
                            ?> 
                        </ul>
                    </div>

我的htaccess代码是

选项+ FollowSymLinks

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
ErrorDocument 404 /404.php

RewriteRule ^([^/]+)/?$ state.php?bnakname=$1 [NC,L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ district.php?bnakname=$1&statename=$2 [NC,L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ branch.php?bnakname=$1&statename=$2&districtname=$3 [NC,L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ ifsc.php?bnakname=$1&statename=$2&districtname=$3&branchname=$4 [NC,L,QSA]

1 个答案:

答案 0 :(得分:0)

您可以使用这两行。检查是否有帮助:

RewriteCond %{QUERY_STRING} "^([^/]*?)(?:/|%20)+([^/]+?(?:/|%20)+.*)$"
RewriteRule ^ %{REQUEST_URI}?%1-%2 [N,NE]

RewriteCond %{QUERY_STRING} "^([^/]*?)(?:/|%20)+([^/]+?)/?$"
RewriteRule ^ %{REQUEST_URI}?%1-%2/ [L,R=302,NE]