.htaccess to re-write incoming requests by inserting “/?load=” after domain name

我们两清 提交于 2019-12-25 01:46:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!