Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP&MySQL url重写问题_Php_Mysql - Fatal编程技术网

PHP&MySQL url重写问题

PHP&MySQL url重写问题,php,mysql,Php,Mysql,例如,我可以使用cat中的值6重写url,并使用PHP和MySQL检查MySQL数据库中的值6类别名称html吗?如果可以,如何 当前url http://localhost/index.php?cat=6&sub1=8&sub2=24&sub3=81 浏览器中显示新的搜索友好URL http://localhost/html/basics/forms/select-tag/ 退房 您需要打开.htaccess文件。如果它不存在,请创建它并包含以下行。请注意,重写引擎

例如,我可以使用cat中的值6重写url,并使用PHP和MySQL检查MySQL数据库中的值6类别名称html吗?如果可以,如何

当前url

http://localhost/index.php?cat=6&sub1=8&sub2=24&sub3=81
浏览器中显示新的搜索友好URL

http://localhost/html/basics/forms/select-tag/
退房

您需要打开.htaccess文件。如果它不存在,请创建它并包含以下行。请注意,重写引擎On只应写入一次

RewriteEngine On # Turn on the rewriting engine 
RewriteRule ^html/basics/forms/select-tag/([0-9]+)/?$ index.php?cat=$1 [NC,L] 

对。基本上,您希望使用mod_rewrite通过路由器脚本传递整个url。.htaccess文件应具有如下内容:

RewriteEngine On
RewriteBase /    

#if it's an existing directory
RewriteCond %{REQUEST_FILENAME} -d [OR] 
#...or an existing file
RewriteCond %{REQUEST_FILENAME} -f 
#serve it up
RewriteRule ^(.+) - [PT,L] 

#else, direct to index.php
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
$request = explode('/', $_GET['url']);
然后,在index.php中,可以有如下内容:

RewriteEngine On
RewriteBase /    

#if it's an existing directory
RewriteCond %{REQUEST_FILENAME} -d [OR] 
#...or an existing file
RewriteCond %{REQUEST_FILENAME} -f 
#serve it up
RewriteRule ^(.+) - [PT,L] 

#else, direct to index.php
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
$request = explode('/', $_GET['url']);
它将在$request数组中包含所有干净的url段。一旦获得这些值,就可以连接到数据库,找到url代表的内容,并输出页面。如果找不到,您可以发送404标头和“未找到页面”消息

header('HTTP/1.0 404 Not Found');
echo '<p>Page not found</p>';
这项基本技术可以通过一些修补来解决您的问题