如何把 example.com/index.php?p=xxx 变成 example.com/xxx/


How to turn example.com/index.php?p=xxx to example.com/xxx/

我该怎么做?有很多关于这个的主题,但我尝试了所有这些主题,但没有奏效。

有人可以给我一个详细而广泛的答案,因为我几乎没有.htaccess经验?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/ index.php?p=$1

从心上看,所以可能需要一些调整

RewriteEngine on
RewriteRule ^([^.]*)/?$ index.php?p=$1 [L]

这将(在内部!)将example.com/xxx发送到/example.com/index.php?p=xxx

因此,在index.php您可以像往常一样对$_GET['p']做任何您想做的事情,但用户会看到该网站index.example.com/xxx