我需要这个脚本来重写一个网址,例如“website.com/index.php?id=1/”到“website.com/1”,但我无法让它工作。为什么这个代码不起作用,我该怎么做才能使它工作?
输入:http://example.com/index.php?id=1 输出:http://example.com/-?id=1
RewriteEngine On
RewriteRule ^index\.php - [L]
RewriteCond ${REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_FILENAME} !-f
RewriteCond ${REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ /index.php?id=$1 [QSA,L]
答案 0 :(得分:0)
您可以使用:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+index\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
RewriteRule ^index\.php - [L]
RewriteCond ${REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_FILENAME} !-f
RewriteCond ${REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ /index.php?id=$1 [QSA,L]