Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
url Slug php和htaccess问题_Php_.htaccess - Fatal编程技术网

url Slug php和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

我试图创建一个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='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。我遇到了相同的问题:'(