htaccess 将 slug 重写为 seo url [英] htaccess rewrite slug to seo url
问题描述
我有一些这样的网址:
www.mydomain/works/show.php?slug=title-of-the-work
www.mydomain/works/show.php?slug=title-of-the-work
我希望以这种方式将 htaccess 转换为 seo URL:
I'll like to have htaccess convert to seo URLs in this way:
www.mydomain/works/title-of-the-work
www.mydomain/works/title-of-the-work
在我的数据库中,我为每个工作条目创建了一个名为 slug 的字段.第一个 URL 工作正常.
In my database I have created a field called slug for every work entry. The first URL works fine.
这是我的 .htaccess 目前的样子(它放在我的根目录中):
This is how my .htaccess currently looks (it is placed in my root directory):
RewriteEngine On
RewriteRule /works/(.*)$ /works/show.php?slug=$1
我在过去 24 小时内阅读并尝试了很多类似的例子,但都无济于事.我确定我的服务器允许重写,因为我可以例如将非 www 重写为 www URL.希望有人能帮忙.谢谢
I've read and tried a lot of similar examples during the last 24hours to no avail. I'm sure my server allows rewriting, because I can for example rewrite non-www to www URLs. Hope someone can help. Thanks
推荐答案
使用:
RewriteEngine On
RewriteRule ^works/(.*)$ works/show.php?slug=$1 [L]
您也可以使用以下代码将 .htaccess 文件放入 works 文件夹:
You can also put your .htaccess file into works folder with this code:
RewriteEngine On
RewriteRule ^(.*)$ show.php?slug=$1 [L]
这篇关于htaccess 将 slug 重写为 seo url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!