我有很多问题都贴在了stackoverflow上,但对我没有帮助,这就是为什么我会严格按照我的要求来尝试。感谢您接受..
我已经尝试了很长时间,但是直到现在我的问题还没有解决。问题是,我试图把我的网址seo友好,如,example.com/articles.php?id=''
到example.com/articles/my-first-article
,而slug是用php生成,并插入到数据库中如下所示。
function php_slug($string){
$spl_char = '/[^\-\s\pN\pL]+/u';
$double_char = '/[\-\s]+/';
$slug = preg_replace('/[^a-z0-9-]+/', '-', strtolower($string));
$slug = preg_replace($double_char, '-', $string);
$slug = trim($string, '-');
return $slug;
}
并包含在HTACCESS中
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [L,QSA]
#RewriteCond %{REQUEST_FILENAME} !-1
#RewriteRule ^/?$ /1 [QSA]
RewriteRule ^article([a-zA-Z0-9-/]+)$ article.php?article_link=$1 [L,QSA]
RewriteRule ^article([a-zA-Z0-9-/]+)/ article.php?article_link=$1 [L,QSA]
并链接为
<a href="article/?article_link='<?php echo $article_link;?>'">BTN</a>
发布于 2019-02-17 15:56:42
请提前重写你的文章:
RewriteEngine On
RewriteRule ^article\/(.*)$ article.php?article_link=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [L,QSA]
将hrefs更改为preety链接(重写应捕获它们):
<a href="article/<?php echo $article_link;?>">BTN</a>
https://stackoverflow.com/questions/54730592
复制相似问题