[英]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.