0

我有点困惑,仍在学习如何在 Apache htaccess 中重写

我怎样才能把这个:

http://www.mydomain.com/dir1/post.php?%20id=1

进入这个:

http://www.mydomain.com/category1/post/1

这是我的参考,我不确定我是否正确

<a href='http://www.mydomain.com/dir1/post.php? id=$id'>
4

1 回答 1

0

如果您只需要重写单个 URL,则可以使用简单的重写规则。

RewriteRule ^dir1/post.php?%20id=1 category1/post/1 [L]

或者您可能需要用空白字符正则表达式替换 %20

RewriteRule ^dir1/post.php?[\s]id=1 category1/post/1 [L]

您需要确保 mod_rewrite 也已打开(.htaccess 中的“RewriteEngine On”)。

这是一个很好的 tut:http ://coding.smashingmagazine.com/2011/11/02/introduction-to-url-rewriting/

于 2013-05-09T16:33:10.747 回答