首页 > 解决方案 > 我更改 URL 类型并使其对 SEO 友好并获得 404

问题描述

在我更改 URL 之前,它就像 https://dastbaz.ir/quotes.php?id=1 然后我使用了这个 PHP 代码

if(isset($_GET['id'])) {

    $stmt = $connection->prepare("XXXXXXXXXXXXXXXXX");
    $stmt->execute();
    $result = $stmt->get_result();
    if ($result->num_rows === 0) exit('No rows');
    $row = fetch_array($result);
    $author_name = $_GET['id']."/".$row['author_name'];
    $journalName = preg_replace('/\s+/', '_', $author_name);

    if (!empty($row)) {
        Header("HTTP/1.1 301 Moved Permanently");
        header("Location: " . $journalName . " ");
    } else {
        $html = "Error: cannot find short URL";
    }
}

并通过在 URL 中使用 id 来选择 author_name 并在 URL 中使用它,现在它就像: https : //dastbaz.ir/1/author_name 但我对.HTACCESS 有问题,我在这些页面上得到 404。如果.HTACCESS 需要任何更改,请帮我处理。htaccess 代码:

AddType application/x-httpd-php56 .php
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*?)$/^(\w+) /quotes.php?id=$1

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^dastbaz.ir/ [NC]
RewriteRule ^(.*)$ https://dastbaz.ir/$1 [L,R=301]

标签: php.htaccessurlurl-rewriting

解决方案


推荐阅读