.htaccess 重写url/blog/article.php?id=hello to/blog/hello.html

.htaccess 重写url/blog/article.php?id=hello to/blog/hello.html,.htaccess,mod-rewrite,url-rewriting,friendly-url,.htaccess,Mod Rewrite,Url Rewriting,Friendly Url,我在.htaccess文件的重定向规则方面遇到了一些问题。 我想创建一个规则,将我的博客内容重定向到一个友好的url。 当前url结构为: /blog/article.php?id=hello 我想把它改成: /blog/hello.html 这是我到目前为止的规则,我似乎无法找到错误: RewriteEngine On Options -MultiViews RewriteRule ^blog/([a-z,A-Z,0-9]+)$.html blog/article.php?id=$1 [L]

我在.htaccess文件的重定向规则方面遇到了一些问题。 我想创建一个规则,将我的博客内容重定向到一个友好的url。 当前url结构为:

/blog/article.php?id=hello

我想把它改成:

/blog/hello.html

这是我到目前为止的规则,我似乎无法找到错误:

RewriteEngine On
Options -MultiViews
RewriteRule ^blog/([a-z,A-Z,0-9]+)$.html blog/article.php?id=$1 [L]

非常感谢您的帮助。

由于您在模式中放置了
$
,因此重写模块无法将您的请求与表达式匹配

应该是:

Options -MultiViews
RewriteEngine On
RewriteRule ^blog/([\da-z]+)\.html$ blog/article.php?id=$1 [L,NC]

这对我似乎不起作用。我正在使用Apache2.4。我在本地主机服务器和真实网页上都尝试了,没有区别。你知道我能做什么吗?谢谢。我碰巧用htaccess生成器解决了这个问题。规则是:RewriteRule^blog/([^/]*)\.html$/blog/articulo.php?id=$1[L]我使用的生成器是:谢谢!