url Slug php和htaccess问题
我试图创建一个slug,从主页跳转到标题为slug的文章页面 以下是我的.htaccess代码:url Slug php和htaccess问题,php,.htaccess,Php,.htaccess,我试图创建一个slug,从主页跳转到标题为slug的文章页面 以下是我的.htaccess代码: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^post/([a-zA-Z0-9_]-)/([0-9]+)\$ article.php?id_art=$1 [NC,L] 这是我的php链接: <a href='article/post/$id_art/$slug'><button class='r
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^post/([a-zA-Z0-9_]-)/([0-9]+)\$ article.php?id_art=$1 [NC,L]
这是我的php链接:
<a href='article/post/$id_art/$slug'><button class='read-more-btn'>Read more</button></a>
url中的slug完全如下所示:
但我得到了这个结果:
找不到对象强>
错误404
伙计们,有什么问题吗?我猜是.htaccess。请帮助这可能是因为您有一个与
^post/
匹配的规则(但您没有文章规则,请尝试重写规则^article/post/([a-zA-Z0-9])/([0-9]+)\$article.php?id\u art=$1
[NC,L]`看看这是否有帮助
您还有
sitename
,这不在规则中。您试图在链接中使用article.php重写的原始url是什么?请尝试将其也包括在内。您的正则表达式是向后的。您有post
然后ID
然后slug
,但您的正则表达式与post
然后slug
(数字/字母/下划线)然后ID
。尝试:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^post/([0-9]+)/([a-zA-Z0-9_-]+)/?$ article.php?id_art=$1 [NC,L]
请注意,您应该得到一个表达式错误:
[a-zA-Z0-9\]-
,该表达式无效。我尝试重写规则^article/post/([a-zA-Z0-9\]/([0-9]+)\$article.php?id\u art=$1[NC,L]
和相同的结果,但站点名称不能在.htaccess中。我在localhost的文章文件夹中有article.php。我遇到了相同的问题:'(