Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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 删除id和?从url到使url seo友好_Php_.htaccess - Fatal编程技术网

Php 删除id和?从url到使url seo友好

Php 删除id和?从url到使url seo友好,php,.htaccess,Php,.htaccess,我正试图设置网址,使其搜索引擎优化友好 我有一个脚本,它显示了一些如下的URL http://example.com/article.php?id=3456/AnimaliaKingdom.html 我正试图让url看起来像这样 http://example.com/article/3456/AnimaliaKingdom.html 或 或 在我的.php文件中,我在标题处使用这个位置 header(“Location: article.php?id=$id/$row[name].html”

我正试图设置网址,使其搜索引擎优化友好

我有一个脚本,它显示了一些如下的URL

http://example.com/article.php?id=3456/AnimaliaKingdom.html
我正试图让url看起来像这样

http://example.com/article/3456/AnimaliaKingdom.html

在我的.php文件中,我在标题处使用这个位置

header(“Location: article.php?id=$id/$row[name].html”);
下面是代码的一部分

$res = SQL_Query_exec("SELECT article.id,article.name WHERE article.id = $id");
$row = mysql_fetch_assoc($res);

if ($_GET["hit"]) {
     SQL_Query_exec("UPDATE article SET views = views + 1 WHERE id = $id");
         header("Location: article.php?id=$id/$row[name].html");
die;
}
这是我使用的重写规则

RewriteEngine On
RewriteRule ^article/(.*?)$ /article.php?id=$1 [L]
我使用了上面的重写规则来重定向路径,但它似乎不起作用


我试过一些类似的问题,但似乎没有任何一个起作用。。。谢谢。

您必须在某些url类中创建链接,如下所示:

<?php
class Url {
    public function link($type, $id, $seo) {
        return "/$type/$id--$seo.html";
    }
}

$url = new Url();
$link_article = $url->link('article', 100, 'friendly-text');
?>
<!DOCTYPE html>
<html>
    <head>
        <title>testing</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="jquery.js" type="text/javascript"></script>
    </head>
    <body>
        <a href="<?php echo $link_article; ?>">Article 100</a>
    </body>
</html>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\w+)/(\d+) $1.php?id=$2&%{QUERY_STRING} [L]

你必须按照你想要的“友好”的方式制作链接,然后将它们重写为php脚本,用标题制作这样的链接是不正确的!为什么要调用
标题(“Location:article.php?id=$id/$row[name].html”)?在这里,您应该向用户发送内容。您是否启用了mod_rewrite?是否允许在配置文件中覆盖所有内容?当你把垃圾代码放进去时,你的.htaccess会产生错误吗?是的,它会带来500个错误…如果没有标题,它会返回一个空白页。。。。顺便说一句,我没有写剧本。。
<?php
class Url {
    public function link($type, $id, $seo) {
        return "/$type/$id--$seo.html";
    }
}

$url = new Url();
$link_article = $url->link('article', 100, 'friendly-text');
?>
<!DOCTYPE html>
<html>
    <head>
        <title>testing</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="jquery.js" type="text/javascript"></script>
    </head>
    <body>
        <a href="<?php echo $link_article; ?>">Article 100</a>
    </body>
</html>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\w+)/(\d+) $1.php?id=$2&%{QUERY_STRING} [L]