Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.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 如何正确实现Apache重写规则?_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php 如何正确实现Apache重写规则?

Php 如何正确实现Apache重写规则?,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,下面是我在.htaccess文件中编写的重写规则代码,该文件位于 β1 文件夹 Options +FollowSymlinks RewriteEngine on RewriteBase /beta1/ RewriteRule /(.*) read.php?post=$1 [R,NC] 当前URL为: 我希望链接显示为: 我是否还需要更改“read.php”从数据库提取数据的方式?如果是的话,怎么办? 我是否还需要对“read.php”文件进行任何更改 上面的重写代码无效。嘿,请尝试此规则

下面是我在.htaccess文件中编写的重写规则代码,该文件位于

β1

文件夹

Options +FollowSymlinks
RewriteEngine on
RewriteBase /beta1/
RewriteRule /(.*) read.php?post=$1 [R,NC]
当前URL为:

我希望链接显示为:

我是否还需要更改“read.php”从数据库提取数据的方式?如果是的话,怎么办? 我是否还需要对“read.php”文件进行任何更改


上面的重写代码无效。

嘿,请尝试此规则

 RewriteEngine On    # Turn on the rewriting engine

 RewriteRule    ^([A-Za-z0-9-_]+)?$    read.php?post=$1    [NC,L]  
和read.php文件

  echo str_replace('-',' ', $_GET['post']); 

如何检查修改是否有效?我是否还需要在read.php中更改/添加任何内容?用.htaccess文件中的代码替换此代码。在read.php文件中,您必须获取$_get数据。您是否检查了read.php文件,并从中获得了结果?我使用$_get['post']获取文章标题;然后对其进行清理,然后从mysql中检索数据。请使用read.php文件的代码添加您的问题。