Apache:.htaccess:SEO:如何消除查询字符串语法 (PHP)

Apache: .htaccess: SEO: how to eliminate query string syntax (PHP)

this post. However, despite trying things as described therein I am still having problems because it seems as though my .htaccess file is not being parsed.

对我的问题提供了很好的帮助

我有一个包含以下页面的网站:

http://mywebsite.com/?menu1=home
http://mywebsite.com/?menu1=posts&menu2=johndoe
http://mywebsite.com/?menu1=posts&menu2=janedoe
http://mywebsite.com/?menu1=posts&menu2=nickdoe
http://mywebsite.com/?menu1=fashion&menu2=armani
http://mywebsite.com/?menu1=fashion&menu2=gucci
http://mywebsite.com/?menu1=about

这些页面通过 Windows 上我的 xampp 目录中的默认 index.php 文件显示。

如何让浏览器响应以下 SEO 友好链接?我希望我的 PHP 代码至少可以修改。

http://mywebsite.com/home
http://mywebsite.com/posts/johndoe
http://mywebsite.com/posts/janedoe
http://mywebsite.com/posts/nickdoe
http://mywebsite.com/fashion/armani
http://mywebsite.com/fashion/gucci
http://mywebsite.com/about

谢谢。

您可以在 Root/.htaccess 中使用这些规则

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /?menu1=&menu2= [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /?menu1= [QSA,NC,L]

第一条规则将“/posts/jondoe/”重写为“/?menu=posts&menu=jonde”,第二条规则将“/about”重写为“/?home=about”..