【问题标题】:.htaccess rewrite rule not working as expected.htaccess 重写规则未按预期工作
【发布时间】:2016-01-20 15:17:54
【问题描述】:
我有一个可点击的文章列表,href 是:/article/article-name
我希望使用 htaccess 文件重定向到 /article/article.php?id = 文章名称
并显示文章/文章名称
我当前的 htaccess 文件是:
RewriteEngine on
RewriteRule ^/(.+)/?$ ./article/article.php?id=$1 [L]
但是这不起作用。
【问题讨论】:
标签:
regex
apache
.htaccess
mod-rewrite
【解决方案1】:
在您的 /article/ 目录中试试这个 .htaccess:
Options -MultiViews
RewriteEngine on
RewriteBase /article/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ article.php?id=$1 [L,QSA]
【解决方案2】:
我的看法
RewriteEngine on
RewriteBase /
RewriteRule ^article/([a-zA-Z0-9\-]+)$ article/article.php?id=$1 [L]