从URL中删除类别sl,然后重定向URL slug

发布于 2025-01-23 07:44:26 字数 930 浏览 2 评论 0原文

我面临一个问题,在哪个类别造成问题的问题:

example.com/category/abc

我希望将其重定向到:domain.com/abc

我的当前.htaccess文件如下:

RewriteEngine On
RewriteBase /
RewriteRule ^category/(.*)$ catlinks.php?id=$1 [L] 
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ show.php?id=$1 [QSA,L]

请注意,当前的URL也是从example.com/category/catlinks.php?id=4 example

>类别:

$stmt = $db->prepare('SELECT * FROM post_category WHERE categorySlug = :categorySlug');
$stmt->execute(array(':categorySlug' => $_GET['id']));
$row = $stmt->fetch();

单一文章类别和文章slug的代码

$stmt = $db->prepare('SELECT * FROM posts WHERE articleSlug = :articleSlug');
$stmt->execute(array(':articleSlug' => $_GET['id']));
$row = $stmt->fetch();

存储在数据库中。

期待答案。

I am facing a problem in which category slug is causing problem:

example.com/category/abc

I want it to be redirected to: domain.com/abc

My current .htaccess file is as follow:

RewriteEngine On
RewriteBase /
RewriteRule ^category/(.*)$ catlinks.php?id=$1 [L] 
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ show.php?id=$1 [QSA,L]

Please note that the current url is also being redirected from example.com/category/catlinks.php?id=4 to example.com/category/abc

Here is the code that is changing the id to slug in category:

$stmt = $db->prepare('SELECT * FROM post_category WHERE categorySlug = :categorySlug');
$stmt->execute(array(':categorySlug' => $_GET['id']));
$row = $stmt->fetch();

Code for single article

$stmt = $db->prepare('SELECT * FROM posts WHERE articleSlug = :articleSlug');
$stmt->execute(array(':articleSlug' => $_GET['id']));
$row = $stmt->fetch();

Category and article slug are stored in database.

Looking forward to an answer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文