【问题标题】:how to remove space in .htaccess using php如何使用php删除.htaccess中的空间
【发布时间】:2014-10-18 23:48:50
【问题描述】:

这是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

那么我该如何解决这个问题

请帮我解决这个问题,谢谢

【问题讨论】:

    标签: php mysql .htaccess redirect url-rewriting


    【解决方案1】:

    听起来您正在尝试使用 SEO/用户友好的网址...如果是这种情况,您必须修改您的网址的生成,如果有空格,请将其替换为字符“-”。我不明白这与 .htaccess 有什么关系...

    但是,您没有指定语言,也没有详细说明您是如何获得这些网址的,所以恐怕这是我在当前状态下可以为您的问题提供的所有帮助。

    【讨论】:

    • 那么解决办法是什么?
    • @user1796164,修改创建你的url的过程,我已经说过了...How取决于你使用的编程语言,使用的框架等等。
    • 好的,我正在使用 php get id $category = $_GET['category']; $model = $_GET['model'];
    • @user1796164,这不是 URL 生成方法。用代码的相关部分更新您的问题,但我相信您应该能够用字符串中的- 替换` `。那里有很多教程可以帮助你,我有点看不出你的问题到底是什么。听起来更像是您从其他人那里获得了代码并且不了解实际发生的情况......
    【解决方案2】:

    如果您想要友好的 URL,最好将所有内容捕获到一个入口点(如 index.php)并在 PHP 中处理 URL,而不是在 .htaccess 上,特别是因为 .htaccess 比 php 慢很多.

    这是我的做法:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-09
      • 2019-08-09
      • 1970-01-01
      • 2013-05-09
      • 2013-04-01
      • 1970-01-01
      • 2021-01-17
      相关资源
      最近更新 更多