[英]how to remove space in .htaccess using php
This is php code 这是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>
i am using this .htaccess file 我正在使用此.htaccess文件
.htaccess .htaccess
RewriteOptions inherit
RewriteRule ^([a-zA-Z0-9_-]+)-([0-9]+)\.html$ detail.php?category=$1&model=$2
it is showing like this 它显示像这样
abc-123.html
and suppose i have a space like this 并假设我有一个这样的空间
abc-123 xyz.html
so it it is not working 所以它不起作用
and it is showing like this 它像这样显示
abc-123%20xyz.html
but no result found 但未找到结果
and i want like this if space is found then showing like this 我想要这样,如果找到了空间,那么就这样显示
abc-123-xyz.html
and if space is not found then showing like this 如果找不到空间,则显示如下
abc-123.html
so how can i fix this issue 所以我该如何解决这个问题
please help me to fix this issue thanks 请帮助我解决此问题,谢谢
Sounds like you're trying to have SEO/User-friendly urls... If that's the case, you must modify the generation of your urls and in case of a space substitute it for a character '-'. 听起来您正在尝试使用SEO /用户友好的网址...如果是这种情况,则必须修改网址的生成,并在空格的情况下用字符“-”代替。 I don't understand what has this to do with .htaccess...
我不知道这与.htaccess有什么关系...
However, you don't specify the language, nor any detail how did you get those urls, so I'm afraid this is all help I can provide to your question in its current state. 但是,您没有指定语言,也没有详细说明如何获取这些url,因此,恐怕这只能为您提供当前状态下的所有帮助。
If you want friendly URL, you are better of just capturing everything to ONE entry point (like index.php) and handling the URL inside the PHP, not on the .htaccess, specially because .htaccess is a lot slower than php. 如果您想要友好的URL,则最好将所有内容捕获到一个入口点(如index.php),并在PHP中处理URL,而不是在.htaccess上,特别是因为.htaccess比php慢得多。
Here is how I do: 这是我的方法:
http://www.prescia.net/bb/coding/5-141018-simple_friendly-url http://www.prescia.net/bb/coding/5-141018-simple_friendly-url
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.