重定向而不改变 URL Apache
Redirect Without changing URL Apache
我想在不更改浏览器的情况下将一个 URL 重定向到另一个 URL
www.example.com/abc/(.*).xml 应该重定向到 www.example.com/abc/xyz/index.htm?文件=$1
但是浏览器应该显示 www.example.com/abc/(.*).xml
您可以使用 RewriteRule
:
RewriteEngine On
RewriteRule /abc/(.*)\.xml$ /abc/xyz/index.htm?file= [L]
确保您已启用 mod_rewrite
并将其放入您的 VirtualHost
配置中,或放入 DocumentRoot
的 .htaccess
文件中
正如 Constantine 在已接受的解决方案上发布的那样,[P] 标志很危险,因为它将服务器转换为代理。
P = Proxy. Forces the rule to be handled by mod_proxy. Transparently provide content from other servers, because your web-server fetches it and re-serves it. This is a dangerous flag, as a poorly written one will turn your web-server into an open-proxy and That is Bad.
我想在不更改浏览器的情况下将一个 URL 重定向到另一个 URL
www.example.com/abc/(.*).xml 应该重定向到 www.example.com/abc/xyz/index.htm?文件=$1
但是浏览器应该显示 www.example.com/abc/(.*).xml
您可以使用 RewriteRule
:
RewriteEngine On
RewriteRule /abc/(.*)\.xml$ /abc/xyz/index.htm?file= [L]
确保您已启用 mod_rewrite
并将其放入您的 VirtualHost
配置中,或放入 DocumentRoot
.htaccess
文件中
正如 Constantine 在已接受的解决方案上发布的那样,[P] 标志很危险,因为它将服务器转换为代理。
P = Proxy. Forces the rule to be handled by mod_proxy. Transparently provide content from other servers, because your web-server fetches it and re-serves it. This is a dangerous flag, as a poorly written one will turn your web-server into an open-proxy and That is Bad.