我需要此脚本来重写诸如" weblity.com/index.php?id=1/"的URL,但我无法让它工作。为什么要做这个代码工作,我该怎么做才能使它起作用?
输入: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]
您可以使用:
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]