REWRITE URL 并在 .htaccess 中保留 QUERY STRING

REWRITE URL and keep QUERY STRING in .htaccess

这是我的 .htaccess 代码...

ErrorDocument 404 /404.html

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI}  !-d
RewriteCond %{REQUEST_URI}  !-f
RewriteCond %{REQUEST_URI}  !\.php$
RewriteCond %{REQUEST_URI}  !\.css$
RewriteCond %{REQUEST_URI}  !\.js$
RewriteCond %{REQUEST_URI}  !\.png$
RewriteCond %{REQUEST_URI}  !\.mp3$
RewriteCond %{REQUEST_URI}  !\.jpg$
RewriteCond %{REQUEST_URI}  !\.html$
RewriteCond %{REQUEST_URI}  !\.xml$
RewriteCond %{REQUEST_URI}  !\.txt$
RewriteCond %{REQUEST_URI}  !\.gif$
RewriteRule  ^(.*)$  /.php  [L]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "https\:\/\/example\.com" [R=301,L]

我想要:example.com/buy?r=abc123 看起来像:example.com/release/abc123 甚至像:example.com/abc123

一旦 url 被重定向,我就无法 $_GET buy.php 中 r 的内容。

希望有人能帮忙:)

如果您想要干净的 URL,那么您可以简单地使用:

RewriteRule ^([^/]*)$ /buy?r= [L]

获得example.com/abc123

或者您可以使用:

RewriteRule ^release/([^/]*)$ /buy?r= [L]

得到example.com/release/abc123.

请确保在测试之前清除缓存。