Mod rewrite mod_rewrite,/index.php?p=test to/test

Mod rewrite mod_rewrite,/index.php?p=test to/test,mod-rewrite,Mod Rewrite,我试图在.htaccess文件中设置一个非常简单的规则,以便将这种url:www.domain.com/index.php?page=test重写为:www.domain.com/test 我是重写mod_的新手,到目前为止,我已经掌握了这个规则 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?$1 但

我试图在.htaccess文件中设置一个非常简单的规则,以便将这种url:www.domain.com/index.php?page=test重写为:www.domain.com/test

我是重写mod_的新手,到目前为止,我已经掌握了这个规则

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


RewriteRule ^(.*)$ index.php?$1
但它不起作用

有什么帮助吗?
非常感谢

几乎正确,您只是忘记了
页面=

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1
现在请注意,此规则的作用正好相反:它在内部将路径请求(如
/test
)重写为
/index.php?page=test
,反之亦然。

另一种方法是:

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^([a-zA-Z0-9-_]+)/?$ index.php?page=$1.php [NC,L]
这也确保了你的URL只能包含字母、数字、破折号和下划线


尽管如此,我还是建议您为每个页面设置单独的文件,并在其中包含header.php和footer.php…

这是一个输入错误:“index.php?1美元”?这应该是“index.php?page=$1”以下链接的目的是什么?只是为了确保URL重写处于活动状态。大多数时候是这样,但有时不是这样。不管怎样,拥有它也没有坏处。