php - 我更改 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]
解决方案
推荐阅读
- angular - 我想从列表 angular 6 中搜索数据
- asp.net-core - 30 分钟后,asp.net 核心身份中缺少其他声明
- laravel - 如果使用 VUE JS 在 s3 中不存在图像,如何设置默认图像
- vue.js - 在vue中加载dom时如何获取dom的高度?
- python - 关于opencv-python 3.4.3
- r - Biostrings::getPromoterSeq 返回查询基因 ID 的多个序列
- reactjs - React TS - 向上传递组件树
- c# - 将 C# Translate Text API 代码从异步转换为 SQL Server CLR 函数的同步
- tuples - 如何在水晶语言的宏中使用构造函数创建一个元组
- assembly - MIPS ASSEMBLY,打印值,突然中断