簡體   English   中英

如何使用PHP刪除.htaccess中的空間

[英]how to remove space in .htaccess using php

這是PHP代碼

$category = $_GET['category'];
    $model = $_GET['model'];
    //connect to database

         mysql_connect('localhost','user','password');
         mysql_select_db('user');


    $result = mysql_query("SET NAMES utf8"); //the main trick
    $q=mysql_query("select * from data where category='$category' And model='$model' AND TRIM(model) IS NOT NULL");

    //Adds one to the counter
     mysql_query("UPDATE daata SET counter = counter + 1 where category='$category' And model='$model'");

     //Retreives the current count
     $count = mysql_fetch_row(mysql_query("SELECT counter FROM data"));
    $row=mysql_fetch_object($q);

    echo mysql_error();


    ?>

    <table class='hovertable'><?php if($row->model):?><tr class=\"style1\"><td width='200'><b>Model:</b></td><td><?php echo $row->model ?></td></tr><?php endif; ?>
    <?php if($row->category):?><tr class=\"style1\"><td width='200'><b>Category:</b></td><td><?php echo $row->category?></td></tr><?php endif; ?></table>

我正在使用此.htaccess文件

.htaccess

RewriteOptions inherit
RewriteRule ^([a-zA-Z0-9_-]+)-([0-9]+)\.html$ detail.php?category=$1&model=$2

它顯示像這樣

abc-123.html

並假設我有一個這樣的空間

abc-123 xyz.html

所以它不起作用

它像這樣顯示

abc-123%20xyz.html

但未找到結果

我想要這樣,如果找到了空間,那么就這樣顯示

abc-123-xyz.html

如果找不到空間,則顯示如下

 abc-123.html

所以我該如何解決這個問題

請幫助我解決此問題,謝謝

聽起來您正在嘗試使用SEO /用戶友好的網址...如果是這種情況,則必須修改網址的生成,並在空格的情況下用字符“-”代替。 我不知道這與.htaccess有什么關系...

但是,您沒有指定語言,也沒有詳細說明如何獲取這些url,因此,恐怕這只能為您提供當前狀態下的所有幫助。

如果您想要友好的URL,則最好將所有內容捕獲到一個入口點(如index.php),並在PHP中處理URL,而不是在.htaccess上,特別是因為.htaccess比php慢得多。

這是我的方法:

http://www.prescia.net/bb/coding/5-141018-simple_friendly-url

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM