从URL中删除类别sl,然后重定向URL slug
我面临一个问题,在哪个类别造成问题的问题:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论