问题
I am in need of some help with coding to rewrite incoming links, this is what I need:
incoming request http://mysite.com/whatever
rewrite to
request http://mysite.com/?load=/whatever
so in a nutshell the incoming links need correcting by adding "/?load=" immediately after the domain name.
The changes are required after making changes to my sites navigation
Any help much appreciated :)
回答1:
Try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /?load=%{REQUEST_URI} [L,QSA]
回答2:
Place these 2 rules:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+\?load=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /?load=/$1 [L,QSA]
来源:https://stackoverflow.com/questions/19532069/htaccess-to-re-write-incoming-requests-by-inserting-load-after-domain-name