.htaccessconfiguration不正常

这是我目前的情况:

Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d [NC] RewriteCond %{REQUEST_FILENAME} !-f [NC] #the rule RewriteRule ^post.php?id=([a-z0-9-]+)$ /post/$1.php # how my url's look like: http://localhost/post.php?id=article-slug-name # how i want them to look like http://localhost/post/article-slug-name ErrorDocument 404 /404.php 

正如它在文件中所说的那样

  • 我的url如何:http://localhost/post.php?id=article-slug-name
  • 我希望他们看起来像http:// localhost / post / article-slug-name

我一直在尝试几天,search所有的论坛,只是不能使它的工作…该文件的作品,因为启用404页面命令我包括在最后的作品。 任何帮助表示赞赏!

我有一段时间没有使用重写规则,但我相信这个命令是:

 RewriteRule reg-exp-source destination 

所以你的规则应该看起来像

 RewriteRule ^post/([a-z0-9-]+)$ post.php?id=$1 

此外,我通常使用条件([^/\.]+) ,以避免拿起另一个斜杠,反斜杠或点后的东西。