且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

重写URL以隐藏真实页面路径

更新时间:2023-11-26 23:10:46

您可以尝试以下方法:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  ^/([^/]+)$
RewriteRule .*  http://whatever.example.com/somepath/whatever/%1 [L]

它将映射:

http://whatever.example.com/anypage

到以下资源:

http://whatever.example.com/somepath/whatever / anypage

始终显示在浏览器的地址栏中:

showing always in the browser's address bar:

http://whatever.example.com/anypage

更新

如果动态内容和替换URI中的内容相同,则还有另一种选择:

If whatever is dynamic and is the same in the substitution URI, here is another option:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST}  ([^/]+)\.example\.com.*
RewriteCond %{REQUEST_URI}  ^/([^/]+)$
RewriteRule .*  http://%1.example.com/somepath/%1/%2 [L]

这将起作用,只要替换路径中的两个 whatever都相同即可。如果不是,则必须对最后的任何内容进行硬编码,如下所示:

This will work as long as both "whatever" in the substitution path are the same. If they are not, the last "whatever" has to be hardcoded, like this:

RewriteRule .*  http://%1.example.com/somepath/whatever/%2 [L]

没有其他方法传入的URL没有它。

There is no other way as the incoming URL doesn't have it.